/* Styles for the /q/{token} quote & proforma-invoice page (plan W10).
 *
 * Separate from src/style.css on purpose: that file is bundled into
 * assets/clicktopay.js and injected into the STOREFRONT too. Page chrome for a
 * page the storefront never renders does not belong in the storefront's bundle.
 * The payment sheet itself is still styled by style.css, because the sheet is
 * shared.
 *
 * Everything here is namespaced .ctpq-* so nothing can collide with the sheet's
 * .ctp-* rules when both are on the page at once.
 */

:root {
  --ctpq-ink: #1e293b;
  --ctpq-muted: #64748b;
  --ctpq-line: #e2e8f0;
  --ctpq-bg: #f1f5f9;
  --ctpq-paper: #ffffff;
  --ctpq-brand: #0e2b5c;   /* LED Light Expert navy */
  /* A quote is an OFFER; a proforma invoice is a numbered document that gets
     filed, forwarded to accounts payable and paid against. They are skinned
     apart so neither can be mistaken for the other at a glance. */
  --ctpq-quote-accent: #64748b;
  --ctpq-brand-ink: #ffffff;
  --ctpq-warn-bg: #fef3c7;
  --ctpq-warn-line: #f59e0b;
  --ctpq-ok-bg: #dcfce7;
  --ctpq-ok-line: #16a34a;
  --ctpq-danger: #b91c1c;
}

/* Store theming (master D14/P6: same payment credentials, different skin). */
#ctp-quote-root[data-store="RG"],
#ctp-landing-root[data-store="RG"] {
  --ctpq-brand: #df1d1d;   /* RuggedGrade red, as in the approved RG email templates */
}

#ctp-quote-root[data-store="RG"] .ctpq-amount-wrap:focus-within {
  box-shadow: 0 0 0 3px rgba(223, 29, 29, 0.14);
}

.ctpq-body {
  margin: 0;
  background: var(--ctpq-bg);
  color: var(--ctpq-ink);
  font-family: "Roboto", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

#ctp-quote-root,
#ctp-landing-root {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.ctpq-doc {
  position: relative;          /* the PAID stamp anchors to this */
  background: var(--ctpq-paper);
  border: 1px solid var(--ctpq-line);
  border-radius: 10px;
  padding: 28px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}

/* --- document type -------------------------------------------------------- */

/* Everything the two documents differ by hangs off this one variable. */
.ctpq-doc[data-doc="quote"]    { --ctpq-doc-accent: var(--ctpq-quote-accent); }
.ctpq-doc[data-doc="proforma"] { --ctpq-doc-accent: var(--ctpq-brand); }

/* A full-bleed band across the top of the sheet, so the FIRST thing read is
   which of the two documents this is. */
.ctpq-doctype {
  /* This is the document's <h1>; the browser's default heading margin and size
     would fight the band, so both are reset here. */
  margin: -28px -28px 22px;
  padding: 11px 28px;
  background: var(--ctpq-doc-accent);
  color: #fff;
  border-radius: 9px 9px 0 0;
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

/* A proforma is the weightier document: solid rule under the header and a
   firmer edge. A quote stays deliberately lighter. */
.ctpq-doc[data-doc="proforma"] { border-color: var(--ctpq-brand); }

/* --- PAID stamp ----------------------------------------------------------- */

/* Only ever rendered on a proforma with nothing left to pay. Sits above the
   document but stays translucent so the figures underneath remain readable,
   and takes no pointer events so it cannot swallow a click. */
.ctpq-stamp {
  position: absolute;
  top: 96px;
  right: 34px;
  z-index: 2;
  transform: rotate(-15deg);
  padding: 4px 20px;
  border: 5px double var(--ctpq-ok-line);
  border-radius: 10px;
  color: var(--ctpq-ok-line);
  font-size: 3rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  opacity: 0.3;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

/* --- header --------------------------------------------------------------- */

.ctpq-head {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 3px solid var(--ctpq-doc-accent, var(--ctpq-brand));
  padding-bottom: 18px;
  margin-bottom: 22px;
}

/* Sized by HEIGHT so the two stores' very different aspect ratios (LLE is
   684x118, RG is 200x120) still produce a header of the same depth. The intrinsic
   width/height attributes in the markup reserve the space, so the header does
   not jump as the image decodes. */
.ctpq-logo {
  display: block;
  height: auto;
  width: auto;
  max-height: 52px;
  max-width: min(320px, 100%);
  margin-bottom: 6px;
}

.ctpq-contact { color: var(--ctpq-muted); font-size: 0.85rem; }

.ctpq-docmeta { text-align: right; }

.ctpq-docnum-label {
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ctpq-muted);
}

.ctpq-docnum { font-size: 1.3rem; font-weight: 700; }
.ctpq-po { font-size: 0.9rem; color: var(--ctpq-muted); }

/* --- banners -------------------------------------------------------------- */

.ctpq-banner {
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 16px;
  border-left: 5px solid transparent;
}

.ctpq-banner-warn { background: var(--ctpq-warn-bg); border-left-color: var(--ctpq-warn-line); }
.ctpq-banner-ok   { background: var(--ctpq-ok-bg);   border-left-color: var(--ctpq-ok-line); }

.ctpq-expiry {
  color: var(--ctpq-muted);
  font-size: 0.85rem;
  margin-bottom: 12px;
  text-align: right;
}

/* --- sections ------------------------------------------------------------- */

.ctpq-section { margin-bottom: 26px; }

.ctpq-section h2 {
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ctpq-muted);
  border-bottom: 1px solid var(--ctpq-line);
  padding-bottom: 6px;
  margin: 0 0 12px;
}

.ctpq-addresses {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.ctpq-address h3 {
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ctpq-muted);
  margin: 0 0 6px;
}

/* --- Bill To editor (plan W10) -------------------------------------------- */

/* The trigger sits inside the "BILL TO" heading, so it must not inherit that
   heading's uppercase letter-spacing -- it is a control, not a label. */
.ctpq-btn-link {
  font: inherit;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: var(--ctpq-brand);
  background: none;
  border: 0;
  padding: 0 0 0 8px;
  cursor: pointer;
  text-decoration: underline;
}

.ctpq-btn-link:hover { color: #1b365d; }

.ctpq-addr-form {
  margin-top: 10px;
  padding: 14px;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
}

/* Two columns on a desktop, one on a phone (the breakpoint below). The two
   long address lines and the help text span the full width. */
.ctpq-addr-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}

.ctpq-addr-street,
.ctpq-addr-street2 { grid-column: 1 / -1; }

.ctpq-addr-field input,
.ctpq-addr-field select {
  width: 100%;
  box-sizing: border-box;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.95rem;
}

.ctpq-addr-field input:focus,
.ctpq-addr-field select:focus {
  outline: 2px solid var(--ctpq-brand);
  outline-offset: 1px;
}

.ctpq-addr-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

/* .ctpq-btn-primary pins itself to the bottom of the pay row; inside this form
   it is just a button in a row. */
.ctpq-addr-actions .ctpq-btn-primary { align-self: auto; }

/* --- tables --------------------------------------------------------------- */

/* Line tables are the one thing allowed to be wider than the page; they get
   their own scroller so the document body never scrolls sideways on a phone. */
.ctpq-table-scroll { overflow-x: auto; }

.ctpq-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

.ctpq-table th {
  text-align: left;
  font-size: 0.72rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ctpq-muted);
  border-bottom: 1px solid var(--ctpq-line);
  padding: 8px 10px;
  white-space: nowrap;
}

.ctpq-table td {
  border-bottom: 1px solid var(--ctpq-line);
  padding: 10px;
  vertical-align: top;
}

.ctpq-num { text-align: right; font-variant-numeric: tabular-nums; }
.ctpq-sku { font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 0.85rem; white-space: nowrap; }
.ctpq-item-name { font-weight: 500; }
.ctpq-item-desc { color: var(--ctpq-muted); font-size: 0.85rem; }
.ctpq-muted { color: var(--ctpq-muted); }
.ctpq-pending-note { color: var(--ctpq-muted); font-size: 0.85rem; }

.ctpq-totals {
  margin-left: auto;
  margin-top: 12px;
  border-collapse: collapse;
  min-width: 280px;
}

.ctpq-totals th {
  text-align: left;
  font-weight: 400;
  color: var(--ctpq-muted);
  padding: 5px 16px 5px 0;
  white-space: nowrap;
}

.ctpq-totals td { padding: 5px 0; font-variant-numeric: tabular-nums; }

.ctpq-totals .ctpq-grand th,
.ctpq-totals .ctpq-grand td {
  border-top: 2px solid var(--ctpq-ink);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ctpq-ink);
  padding-top: 8px;
}

/* --- pay box -------------------------------------------------------------- */

.ctpq-pay {
  background: #f8fafc;
  border: 1px solid var(--ctpq-line);
  border-radius: 8px;
  padding: 18px;
}

.ctpq-pay h2 { border-bottom: none; margin-bottom: 10px; }

.ctpq-pay-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-end;
}

.ctpq-field { flex: 1 1 220px; }

.ctpq-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  margin-bottom: 4px;
}

.ctpq-amount-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0 12px;
}

.ctpq-amount-wrap:focus-within { border-color: var(--ctpq-brand); box-shadow: 0 0 0 3px rgba(14, 43, 92, 0.12); }

.ctpq-amount-wrap input {
  border: 0;
  outline: none;
  padding: 12px 0;
  font-size: 1.15rem;
  width: 100%;
  font-variant-numeric: tabular-nums;
  background: transparent;
  color: inherit;
}

.ctpq-help { color: var(--ctpq-muted); font-size: 0.82rem; margin-top: 6px; }
.ctpq-error { color: var(--ctpq-danger); font-size: 0.88rem; margin-top: 8px; font-weight: 500; }

.ctpq-btn {
  display: inline-block;
  background: #fff;
  color: var(--ctpq-brand);
  border: 1px solid var(--ctpq-brand);
  border-radius: 6px;
  padding: 13px 22px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  font-family: inherit;
}

.ctpq-btn:hover { background: #eef2f7; }
.ctpq-btn:disabled { opacity: 0.55; cursor: not-allowed; }

.ctpq-btn-primary {
  background: var(--ctpq-brand);
  color: var(--ctpq-brand-ink);
  align-self: flex-end;
  min-width: 150px;
}

.ctpq-btn-primary:hover { background: #1b365d; }

.ctpq-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 8px;
}

.ctpq-foot {
  margin-top: 26px;
  padding-top: 14px;
  border-top: 1px solid var(--ctpq-line);
  color: var(--ctpq-muted);
  font-size: 0.85rem;
}

/* --- loading / failure ---------------------------------------------------- */

.ctpq-loading { text-align: center; padding: 80px 20px; color: var(--ctpq-muted); }

.ctpq-spinner {
  width: 34px; height: 34px;
  margin: 0 auto 16px;
  border: 4px solid var(--ctpq-line);
  border-top-color: var(--ctpq-brand);
  border-radius: 50%;
  animation: ctpq-spin 0.9s linear infinite;
}

@keyframes ctpq-spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .ctpq-spinner { animation-duration: 4s; }
}

/* The failure page and the host landing page: one centred card, branded by
   host (data-store on the mount element), neutral on an unknown host. */
.ctpq-notice { text-align: center; max-width: 560px; margin: 24px auto 0; padding: 32px 24px; }
.ctpq-notice h1 { color: var(--ctpq-brand); font-size: 1.4rem; line-height: 1.25; margin: 0 0 12px; }
.ctpq-notice h2 { color: var(--ctpq-ink); font-size: 1.05rem; margin: 0 0 8px; }
.ctpq-notice p { color: var(--ctpq-muted); margin: 0 0 12px; }
.ctpq-notice-logo { display: block; max-width: 220px; width: 100%; height: auto; margin: 0 auto 24px; }
.ctpq-actions { list-style: none; margin: 20px 0 8px; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.ctpq-action {
  display: inline-block; padding: 11px 18px; border-radius: 6px;
  background: var(--ctpq-brand); color: var(--ctpq-brand-ink);
  font-weight: 700; text-decoration: none; overflow-wrap: anywhere;
}
.ctpq-action:hover { filter: brightness(1.1); }
.ctpq-action:focus-visible, .ctpq-site a:focus-visible { outline: 3px solid var(--ctpq-ink); outline-offset: 2px; }
.ctpq-site { margin: 12px 0 0; }
.ctpq-site a { color: var(--ctpq-brand); font-weight: 500; }
.ctpq-store { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--ctpq-line); }
.ctpq-store:first-of-type { border-top: 0; padding-top: 0; }

/* --- phone ---------------------------------------------------------------- */

@media (max-width: 640px) {
  #ctp-quote-root,
  #ctp-landing-root { padding: 12px 12px 48px; }
  .ctpq-doc { padding: 18px 14px; border-radius: 8px; }
  .ctpq-notice { margin-top: 8px; padding: 24px 16px; }
  .ctpq-actions { flex-direction: column; }
  .ctpq-action { display: block; }
  .ctpq-addresses { grid-template-columns: 1fr; }
  .ctpq-docmeta { text-align: left; }
  .ctpq-expiry { text-align: left; }
  .ctpq-totals { min-width: 0; width: 100%; }
  .ctpq-btn-primary { width: 100%; }
  .ctpq-addr-grid { grid-template-columns: 1fr; }
  /* The actions row inherits width:100% from the rule above, which would stack
     Save and Cancel; they are a pair and belong side by side even on a phone. */
  .ctpq-addr-actions .ctpq-btn { flex: 1 1 0; width: auto; min-width: 0; }
  /* The band bleeds to the card edge, so its negative margins must track the
     card's padding -- which this breakpoint changes. */
  .ctpq-doctype { margin: -18px -14px 18px; padding: 9px 14px; }
  .ctpq-logo { max-height: 44px; }
  .ctpq-stamp { top: 78px; right: 14px; font-size: 2rem; border-width: 4px; padding: 3px 14px; }
}

/* --- print (plan W10: hide chrome, force light, real margins) ------------- */

@media print {
  .ctpq-body { background: #fff; font-size: 11pt; }

  /* Interactive chrome has no meaning on paper; the pay box least of all. */
  .ctpq-noprint,
  .ctpq-pay,
  #clicktopay-modal-overlay { display: none !important; }

  #ctp-quote-root { max-width: none; padding: 0; }

  .ctpq-doc { border: 0; box-shadow: none; padding: 0; border-radius: 0; }

  /* Same reason as the mobile override: printing zeroes the card padding, so
     the full-bleed band has nothing to bleed into. On paper it becomes a plain
     ruled heading, which also survives a printer that drops backgrounds. */
  .ctpq-doctype {
    margin: 0 0 14px;
    padding: 0 0 8px;
    background: none;
    color: #000;
    border-bottom: 2px solid #000;
    border-radius: 0;
  }

  /* The stamp DOES print: a proforma saved as a PDF and forwarded to accounts
     payable is exactly where "this is already paid" has to be visible. Printers
     drop backgrounds by default, so ask for colour explicitly. */
  .ctpq-stamp {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    opacity: 0.35;
  }

  /* Banners still print: "this document is out of date" must survive being
     saved as a PDF and forwarded, which is exactly when it matters most. */
  .ctpq-banner { border: 1px solid #999; border-left-width: 5px; }

  .ctpq-table { font-size: 10pt; }
  .ctpq-table-scroll { overflow: visible; }

  /* Keep a line item and its totals off a page break where we can. */
  tr, .ctpq-address, .ctpq-totals { break-inside: avoid; }
  thead { display: table-header-group; }

  a[href]::after { content: ""; }  /* no URL footnotes: they would print the token */
}

@page { margin: 14mm; }
