/* =====================================================================
   Billing UI — ls-billing-panel and ls-payment-element.
   Ported verbatim from the approved artifacts:
     design/leadsurface/artifacts/billing-panel.html
     design/leadsurface/artifacts/payment-element.html
   The artifacts' spec-sheet chrome (.spec-*) and the mock of Stripe's
   iframe interior (.mock-*, .scrim) are deliberately NOT ported — the mock
   cannot affect the real Element and exists only so the artifact reads as
   a screen.
   ===================================================================== */

/* =====================================================================
   ls-billing-panel
   ===================================================================== */
.bill {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.bill-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
}

/* --- header: plan name, price, lifecycle status --- */
.bill-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}
.bill-plan h3 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-hi);
}
.bill-price {
  display: block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-3);
  letter-spacing: 0.02em;
}

/* Lifecycle status pill. Deliberately NOT .badge — .badge variants are
   the signal-intent rail (switching/comparison/complaint/praise) and
   reusing them here would overload a functional color system. Every
   ink/tint pair below is >= 4.5:1 (see artifacts/README.md § contrast). */
.st {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text-3);
  white-space: nowrap;
}
.st::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
  flex-shrink: 0;
}
.st-trial {
  color: #0f766e; /* --accent · 4.76:1 on its own tint */
  background: rgba(15, 118, 110, 0.1);
  border-color: rgba(15, 118, 110, 0.25);
}
.st-active {
  color: #047857; /* 4.91:1 on the green tint — NOT --green #10b981 */
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.28);
}
.st-due {
  color: #b45309; /* 4.58:1 on the amber tint */
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.28);
}
.st-locked {
  color: #b91c1c; /* 5.66:1 on the red tint — NOT --red #ef4444 */
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.25);
}
.st-ended {
  color: var(--text-3); /* 4.95:1 on --panel-2 */
}
.st-founder {
  color: #a16207; /* 4.92:1 on white; gold echoes the admin founder chip */
  background: rgba(234, 179, 8, 0.12);
  border-color: rgba(234, 179, 8, 0.3);
}

/* --- trial countdown ---
   The bar is decoration: the sentence above it carries the value, and
   the bar repeats it for role=progressbar. Fill-vs-track is >= 3:1
   (WCAG 1.4.11) in all three variants. */
.bill-trial {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.bill-trial-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.bill-trial-line strong {
  font-family: var(--font-display);
  font-size: 15px;
  color: var(--text-hi);
}
.bill-trial-line .when {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-3);
}
.meter {
  height: 8px;
  border-radius: 999px;
  background: var(--panel-3);
  overflow: hidden;
}
.meter > i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--accent); /* 4.44:1 vs the track */
}
.meter.warn > i {
  background: #b45309; /* 4.07:1 vs the track — --amber is only 1.74:1 */
}
.meter.crit > i {
  background: var(--red); /* 3.05:1 vs the track */
}
.bill-trial p {
  margin: 10px 0 0;
  font-size: 13.5px;
  color: var(--text);
}

/* --- facts grid: card on file, next invoice, period end --- */
.bill-grid {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 12px 20px;
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
/* Used when the grid is the FIRST block after the head — the artifact writes
   this as an inline style in four states; promoted to a modifier so no
   component ships inline styles. */
.bill-grid.flush {
  border-top: 0;
  padding-top: 6px;
  margin-top: 12px;
}
.bill-grid dt {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-3);
  align-self: center;
}
.bill-grid dd {
  margin: 0;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.bill-grid dd .none {
  color: var(--text-3);
}
.card-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--text-hi);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 9px;
}
.card-chip .brand {
  text-transform: uppercase;
  font-weight: 600;
}
.card-chip svg {
  color: var(--text-3);
}
.exp {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-3);
}
.exp.soon {
  color: #b45309;
}

/* --- notices: thin LEFT RULE + hairline box, never a color fill.
       DESIGN.md § Callouts. --- */
.bill-note {
  display: flex;
  gap: 12px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--muted);
  border-radius: var(--radius);
}
.bill-note .ic {
  flex-shrink: 0;
  margin-top: 2px;
  color: var(--text-3);
}
.bill-note h4 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-hi);
  letter-spacing: -0.01em;
}
.bill-note p {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--text);
}
.bill-note p + p {
  margin-top: 8px;
}
.bill-note .row {
  margin-top: 12px;
}
.bill-note.warn {
  border-left-color: var(--amber);
}
.bill-note.warn .ic {
  color: #b45309;
}
.bill-note.crit {
  border-left-color: var(--red);
}
.bill-note.crit .ic {
  color: #b91c1c;
}
.bill-note.ok {
  border-left-color: var(--green);
}
.bill-note.ok .ic {
  color: #047857;
}
.bill-note.info {
  border-left-color: var(--accent);
}
.bill-note.info .ic {
  color: var(--accent);
}

/* --- actions --- */
.bill-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px 16px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.bill-actions.flush {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}
/* The Stripe hand-off. The destination is named in the button, repeated
   in a hint below it, and marked with an external-link glyph — because
   there is no billing.leadsurface.com yet and an unannounced jump to
   billing.stripe.com reads as a phish. Spec #11 § Portal presentation. */
/* Claims the whole .bill-actions row. As an ordinary flex item it was
   shrink-to-fit — sized by the button, with the explanation wrapped into that
   same narrow column while the rest of the panel ran full width. The button
   keeps its natural size via align-items: flex-start; the hint gets its own
   42ch measure. */
.handoff {
  display: flex;
  flex-direction: column;
  gap: 7px;
  align-items: flex-start;
  flex: 1 1 100%;
  min-width: 0;
}
.hint {
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--text-3);
  max-width: 42ch;
}
button .ext,
.btn-link .ext {
  flex-shrink: 0;
  opacity: 0.85;
}
.btn-link {
  background: none;
  border: 0;
  padding: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  text-decoration: none;
}
.btn-link:hover {
  box-shadow: none;
  transform: none;
  color: var(--accent-2);
  text-decoration: underline;
}
/* Focus: components.css sets no :focus-visible on button, so state it
   here. Scoped to the billing surfaces on purpose — making it global is
   design-system gap G1 and belongs in its own change. */
.bill button:focus-visible,
.bill a:focus-visible,
.bill summary:focus-visible,
.lockwrap button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* --- inline "add a card" disclosure --- */
.bill-addcard {
  margin-top: 16px;
  border: 1px solid var(--border-accent);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}
.bill-addcard > summary {
  list-style: none;
  cursor: pointer;
  padding: 13px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  color: var(--accent);
  background: var(--accent-soft);
}
.bill-addcard > summary::-webkit-details-marker {
  display: none;
}
.bill-addcard > summary .chev {
  margin-left: auto;
  transition: transform 0.15s;
}
.bill-addcard[open] > summary .chev {
  transform: rotate(180deg);
}
.bill-addcard .body {
  padding: 18px 16px 16px;
  border-top: 1px solid var(--border-accent);
}
.bill-addcard .body > p {
  margin: 0 0 14px;
  font-size: 13.5px;
  color: var(--text);
}

/* --- skeleton --- */
.sk {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--panel-2), var(--panel-3), var(--panel-2));
  background-size: 200% 100%;
  animation: sk 1.4s ease-in-out infinite;
}
@keyframes sk {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}
/* tokens.css already forces prefers-reduced-motion to ~0s globally, which
   freezes the sweep. Hold a flat fill so it doesn't read as a stuck bar. */
@media (prefers-reduced-motion: reduce) {
  .sk {
    background: var(--panel-2);
  }
}

/* --- locked (402) interstitial: the whole-app state, not a panel --- */
.lockwrap {
  max-width: 560px;
  margin: 0 auto;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
}
.lockwrap .ic {
  width: 46px;
  height: 46px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(239, 68, 68, 0.1);
  color: #b91c1c;
  margin-bottom: 16px;
}
.lockwrap h3 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 24px;
  letter-spacing: -0.02em;
  color: var(--text-hi);
}
.lockwrap > p {
  margin: 0 auto 22px;
  max-width: 44ch;
  color: var(--text);
  font-size: 15px;
}
.lockwrap .keeps {
  list-style: none;
  padding: 16px 0 0;
  margin: 22px 0 0;
  border-top: 1px solid var(--border);
  text-align: left;
  display: grid;
  gap: 8px;
  font-size: 13.5px;
  color: var(--text);
}
.lockwrap .keeps li {
  display: flex;
  gap: 9px;
  align-items: flex-start;
}
.lockwrap .keeps .ok {
  color: #047857;
  flex-shrink: 0;
}

/* =====================================================================
   ls-payment-element — the FRAME. Everything Stripe renders lives inside
   .pe-mount and is unreachable from this stylesheet; it is configured
   through the Appearance API object in ls-payment-element.js instead.
   ===================================================================== */
.pay {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}
/* Nested inside the billing panel's disclosure, the frame is the disclosure
   body — it must not draw a second card edge inside one. */
.bill-addcard .pay {
  border: 0;
  padding: 0;
  border-radius: 0;
}
.pay-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}
.pay-label {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-hi);
  letter-spacing: -0.01em;
}
/* The trust line. Small, mono, never a lock emoji — SVG line art only. */
.pay-secure {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--text-3);
  white-space: nowrap;
}
.pay-secure svg {
  color: #047857;
}
.pay-hint {
  margin: 0 0 14px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
}

/* The mount point. Fixed min-height so the Element's async render never
   shifts the page (Stripe reflows it as payment methods resolve). Border
   + fill are ours; everything inside is Stripe's iframe.
   No overflow clipping (clips the wallet sheet), no filter/transform/zoom
   (breaks hit-testing and overlay positioning), min-height never height
   (the Element grows). */
.pe-mount {
  min-height: 190px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 14px;
  position: relative;
}
/* No :focus-within ring on the mount. The iframe owns focus and draws its
   own ring via appearance.variables.focusBoxShadow — an outer ring would
   double up and mis-report which field is active. */
.pe-mount.is-busy {
  opacity: 0.55;
  pointer-events: none;
}
.pe-mount.is-dead {
  border-style: dashed;
  border-color: rgba(239, 68, 68, 0.4);
  background: var(--panel-2);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
}
.pe-dead-title {
  margin: 0 0 6px;
  font-size: 14px;
  color: var(--text-hi);
  font-weight: 600;
}
.pe-dead-body {
  margin: 0;
  font-size: 13px;
  color: var(--text);
  max-width: 42ch;
}
.pe-dead-body code {
  font-family: var(--font-mono);
  font-size: 12.5px;
}

/* Form-level error — OURS. Field-level errors ("Your card number is
   incomplete") are drawn by Stripe inside the iframe; this slot carries
   only what confirmSetup/confirmPayment returns. It is always in the DOM
   so the busy button never jumps when a message appears. */
.pe-error {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  min-height: 20px;
  margin-top: 12px;
  font-size: 13.5px;
  line-height: 1.55;
  color: #b91c1c; /* 6.47:1 on --panel — not --red #ef4444 (3.76:1) */
}
.pe-error:empty {
  margin-top: 0;
}
.pe-error svg {
  flex-shrink: 0;
  margin-top: 2px;
}
.pe-error a {
  color: inherit;
}

.pe-ok {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  margin-top: 12px;
  font-size: 13.5px;
  line-height: 1.55;
  color: #047857; /* 5.48:1 on --panel */
}
.pe-ok svg {
  flex-shrink: 0;
  margin-top: 2px;
}

.pay-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  flex-wrap: wrap;
}
/* 44px, not 40: this rule outranks the base button floor in components.css,
   and Save card is the last control before money moves. */
.pay-actions button {
  min-height: 44px;
}
.pay-actions button[aria-disabled='true'],
.pay-actions button:disabled {
  opacity: 0.6;
  cursor: progress;
  box-shadow: none;
  transform: none;
}
.pay-actions button:focus-visible,
.pay a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.spin {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  animation: sp 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes sp {
  to {
    transform: rotate(360deg);
  }
}
/* tokens.css kills animation globally under reduced-motion; the spinner
   would freeze mid-arc. Swap it for a static ring — the button label and
   aria-busy already say "working". */
@media (prefers-reduced-motion: reduce) {
  .spin {
    border-color: rgba(255, 255, 255, 0.55);
    border-top-color: #fff;
  }
}
.pay-legal {
  margin: 14px 0 0;
  padding-top: 13px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-3);
}
.pay-legal a {
  color: var(--accent);
}

/* --- responsive --- */
@media (max-width: 560px) {
  .bill-panel {
    padding: 18px 16px;
  }
  .bill-grid {
    grid-template-columns: 1fr;
    gap: 4px 0;
  }
  .bill-grid dt {
    margin-top: 10px;
  }
  .bill-grid dt:first-child {
    margin-top: 0;
  }
  .bill-actions > button,
  .bill-actions .handoff,
  .bill-actions .handoff > button {
    width: 100%;
  }
  .bill-actions .handoff .hint {
    max-width: none;
  }
  .bill-head {
    flex-direction: column;
  }
  .pay {
    padding: 16px;
  }
  .pay-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  .pay-actions,
  .pay-actions button {
    width: 100%;
    justify-content: center;
  }
}
