/*
 * Yoda Bill usage billing (lot 15): "Subscription & payment" section, card dialog, shell banner.
 * The usage of the month is a ticket with a perforated stub, read like the price simulator of the public site.
 */

/* ---------- Usage ticket ---------- */
.yb-usage {
  container-type: inline-size;
  --yb-usage-stub: 272px;
  --yb-usage-notch-bg: var(--yb-bg);
}

.yb-usage__ticket {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--yb-usage-stub);
  overflow: hidden;
  border: 1px solid var(--yb-border);
  border-radius: var(--yb-radius-md);
  background: var(--yb-surface);
}

/* Notches cut on the perforation line, top and bottom. */
.yb-usage__ticket::before,
.yb-usage__ticket::after {
  content: "";
  position: absolute;
  left: calc(100% - var(--yb-usage-stub) - 9px);
  z-index: 1;
  width: 18px;
  height: 18px;
  border: 1px solid var(--yb-border);
  border-radius: var(--yb-radius-pill);
  background: var(--yb-usage-notch-bg);
}

.yb-usage__ticket::before {
  top: -10px;
}

.yb-usage__ticket::after {
  bottom: -10px;
}

.yb-usage__body {
  min-width: 0;
  padding: var(--yb-space-6) var(--yb-space-6) var(--yb-space-5);
}

.yb-usage__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--yb-space-1) var(--yb-space-3);
}

.yb-usage__title {
  font-size: var(--yb-text-title-2);
  line-height: var(--yb-leading-title-2);
  font-weight: var(--yb-weight-title-2);
  letter-spacing: var(--yb-tracking-title-2);
}

.yb-usage__period {
  color: var(--yb-text-muted);
  font-size: var(--yb-text-caption);
}

.yb-usage__count {
  display: flex;
  align-items: baseline;
  gap: var(--yb-space-2);
  margin-top: var(--yb-space-4);
}

.yb-usage__number {
  font-size: var(--yb-text-amount-hero);
  line-height: var(--yb-leading-amount-hero);
  font-weight: var(--yb-weight-strong);
  letter-spacing: -0.02em;
}

.yb-usage__unit {
  color: var(--yb-text-muted);
}

/* The meter: free zone (green tint), cap zone (saffron tint), usage (petrol) and its thumb. */
.yb-usage__meter {
  --yb-thumb: 18px;
  position: relative;
  margin-top: var(--yb-space-3);
  padding-bottom: 34px;
}

.yb-usage__track {
  position: relative;
  height: 10px;
  margin-inline: calc(var(--yb-thumb) / 2);
  border-radius: var(--yb-radius-pill);
  background: var(--yb-bg-sunken);
  box-shadow: inset 0 0 0 1px var(--yb-border);
}

.yb-usage__zone,
.yb-usage__fill {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: var(--yb-radius-pill);
}

.yb-usage__zone--free {
  left: 0;
  width: calc(var(--yb-usage-free) * 1%);
  background: var(--yb-success-soft);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--yb-success) 25%, transparent);
}

.yb-usage__zone--cap {
  left: calc(var(--yb-usage-cap) * 1%);
  right: 0;
  background: var(--yb-accent-soft);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--yb-accent) 45%, transparent);
}

.yb-usage__fill {
  left: 0;
  width: calc(var(--yb-usage-p) * 1%);
  background: var(--yb-primary);
  transition: width var(--yb-duration-slow) var(--yb-ease);
}

.yb-usage__thumb {
  position: absolute;
  top: 50%;
  left: calc(var(--yb-usage-p) * 1%);
  width: var(--yb-thumb);
  height: var(--yb-thumb);
  border: 3px solid var(--yb-primary);
  border-radius: var(--yb-radius-pill);
  background: var(--yb-surface);
  transform: translate(-50%, -50%);
  transition: left var(--yb-duration-slow) var(--yb-ease);
}

.yb-usage[data-state="zero"] .yb-usage__thumb {
  border-color: var(--yb-border-input);
}

.yb-usage[data-state="cap"] .yb-usage__fill {
  background: linear-gradient(to right, var(--yb-primary) calc(var(--yb-usage-cap) / var(--yb-usage-p) * 100%), var(--yb-accent) 0);
}

.yb-usage[data-state="cap"] .yb-usage__thumb {
  border-color: var(--yb-accent);
}

.yb-usage__marks {
  position: absolute;
  inset: 16px calc(var(--yb-thumb) / 2) 0;
}

.yb-usage__mark {
  position: absolute;
  left: calc(var(--yb-mark-p) * 1%);
  padding-top: 8px;
  color: var(--yb-text-muted);
  font-size: var(--yb-text-caption);
  white-space: nowrap;
  transform: translateX(-50%);
}

.yb-usage__mark::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  width: 2px;
  height: 6px;
  border-radius: 1px;
  background: var(--yb-border-strong);
}

/* The free mark is close to the start: its label hangs to the right of its tick. */
.yb-usage__mark--free {
  transform: translateX(-1px);
}

.yb-usage__mark--free::before {
  left: 0;
}

.yb-usage__note {
  max-width: 62ch;
  margin-top: var(--yb-space-2);
  color: var(--yb-text-muted);
  font-size: var(--yb-text-caption);
  line-height: var(--yb-leading-caption);
}

/* Stub: the estimate of the month, separated by the perforation. */
.yb-usage__stub {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--yb-space-1);
  padding: var(--yb-space-6);
  border-radius: 0 var(--yb-radius-md) var(--yb-radius-md) 0;
  background: var(--yb-bg-sunken);
}

.yb-usage__stub::before {
  content: "";
  position: absolute;
  top: 12px;
  bottom: 12px;
  left: -4px;
  width: 8px;
  background: radial-gradient(circle, var(--yb-border-strong) var(--yb-perforation-dot), transparent calc(var(--yb-perforation-dot) + 0.5px)) 50% 0 / 8px var(--yb-perforation-gap) repeat-y;
}

.yb-usage__label {
  color: var(--yb-text-muted);
  font-size: var(--yb-text-caption);
  font-weight: var(--yb-weight-medium);
}

.yb-usage__amount {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 6px;
  margin-block: 2px var(--yb-space-1);
  font-size: 2.125rem;
  line-height: 1.1;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.yb-usage__currency {
  color: var(--yb-text-muted);
  font-size: 1rem;
  font-weight: var(--yb-weight-strong);
  letter-spacing: 0;
}

.yb-usage[data-state="zero"] .yb-usage__value,
.yb-usage[data-state="free"] .yb-usage__value {
  color: var(--yb-success);
}

.yb-usage__explain {
  font-weight: var(--yb-weight-medium);
}

.yb-usage[data-state="cap"] .yb-usage__explain {
  color: var(--yb-on-accent-soft);
}

.yb-usage__charge {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  margin-top: var(--yb-space-2);
  color: var(--yb-text-muted);
  font-size: var(--yb-text-caption);
  line-height: var(--yb-leading-caption);
}

.yb-usage__charge .mud-icon-root {
  flex: none;
  font-size: 16px;
}

/* The only stamp of the section: the monthly cap is reached. */
.yb-usage__stamp {
  align-self: center;
  margin-left: var(--yb-space-2);
  padding: 3px 9px;
  letter-spacing: 0;
  white-space: nowrap;
  border: 2px solid var(--yb-accent);
  border-radius: var(--yb-radius-sm);
  color: var(--yb-on-accent-soft);
  background: var(--yb-accent-soft);
  font-size: var(--yb-text-caption);
  font-weight: 650;
  transform: rotate(-5deg);
}

.yb-usage--skeleton .yb-usage__body,
.yb-usage--skeleton .yb-usage__stub {
  min-height: 180px;
}

/* Narrow: the stub goes below the ticket, perforated along its top edge. */
@container (max-width: 620px) {
  .yb-usage__ticket {
    grid-template-columns: minmax(0, 1fr);
  }

  .yb-usage__ticket::before,
  .yb-usage__ticket::after {
    display: none;
  }

  .yb-usage__body {
    padding: var(--yb-space-5) var(--yb-space-4) var(--yb-space-4);
  }

  .yb-usage__stub {
    padding: var(--yb-space-5) var(--yb-space-4);
    border-radius: 0 0 var(--yb-radius-md) var(--yb-radius-md);
  }

  .yb-usage__stub::before {
    top: -4px;
    right: 12px;
    bottom: auto;
    left: 12px;
    width: auto;
    height: 8px;
    background: radial-gradient(circle, var(--yb-border-strong) var(--yb-perforation-dot), transparent calc(var(--yb-perforation-dot) + 0.5px)) 0 50% / var(--yb-perforation-gap) 8px repeat-x;
  }
}

/* ---------- Alert of the section ---------- */
.yb-billing-alert {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--yb-space-3) var(--yb-space-4);
  padding: var(--yb-space-4) var(--yb-space-5);
  border: 1px solid;
  border-radius: var(--yb-radius-md);
}

.yb-billing-alert--blocked {
  border-color: color-mix(in srgb, var(--yb-error) 45%, transparent);
  background: var(--yb-error-soft);
}

.yb-billing-alert--due {
  border-color: color-mix(in srgb, var(--yb-warning) 40%, transparent);
  background: var(--yb-warning-soft);
}

.yb-billing-alert__icon.mud-icon-root {
  flex: none;
  margin-top: 1px;
}

.yb-billing-alert--blocked .yb-billing-alert__icon {
  color: var(--yb-error);
}

.yb-billing-alert--due .yb-billing-alert__icon {
  color: var(--yb-warning);
}

.yb-billing-alert__text {
  flex: 1 1 320px;
  min-width: 0;
}

.yb-billing-alert__title {
  margin-bottom: 2px;
  font-weight: var(--yb-weight-strong);
}

.yb-billing-alert__owner {
  margin-top: var(--yb-space-1);
  color: var(--yb-text-muted);
  font-size: var(--yb-text-caption);
}

.yb-billing-alert__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--yb-space-2);
  margin-left: calc(20px + var(--yb-space-4));
}

/* ---------- Gateway mode (development / Stripe test) ---------- */
.yb-gateway-note {
  display: flex;
  align-items: flex-start;
  gap: var(--yb-space-2);
  padding: var(--yb-space-2) var(--yb-space-3);
  border: 1px dashed var(--yb-border-strong);
  border-radius: var(--yb-radius-sm);
  color: var(--yb-text-muted);
  font-size: var(--yb-text-caption);
  line-height: var(--yb-leading-caption);
}

.yb-gateway-note .mud-icon-root {
  flex: none;
  font-size: 16px;
}

.yb-gateway-note strong {
  color: var(--yb-text);
}

.yb-gateway-note--fake {
  border-color: var(--yb-accent);
  background: var(--yb-accent-soft);
  color: var(--yb-on-accent-soft);
}

.yb-gateway-note--fake strong {
  color: inherit;
}

.yb-gateway-note--banner {
  margin: var(--yb-space-4) var(--yb-space-5) 0;
}

/* ---------- Payment methods ---------- */
.yb-cards {
  margin: 0;
  padding: var(--yb-space-2) 0;
  list-style: none;
}

.yb-cards__item {
  display: flex;
  align-items: center;
  gap: var(--yb-space-3);
  min-height: 60px;
  padding: var(--yb-space-2) var(--yb-space-3) var(--yb-space-2) var(--yb-space-5);
}

.yb-cards__item + .yb-cards__item {
  border-top: 1px solid var(--yb-border);
}

/* A small card drawn in CSS (brand names stay in the text, no logos). */
.yb-card-chip {
  position: relative;
  flex: none;
  width: 40px;
  height: 28px;
  border: 1px solid var(--yb-border-strong);
  border-radius: 5px;
  background: var(--yb-bg-sunken);
  font-size: 0;
}

.yb-card-chip::before {
  content: "";
  position: absolute;
  top: 7px;
  left: 6px;
  width: 9px;
  height: 7px;
  border-radius: 2px;
  background: var(--yb-accent);
}

.yb-card-chip::after {
  content: "";
  position: absolute;
  right: 6px;
  bottom: 6px;
  left: 6px;
  height: 2px;
  border-radius: 1px;
  background: var(--yb-border-strong);
}

.yb-cards__item--default .yb-card-chip {
  border-color: var(--yb-primary);
  background: var(--yb-primary);
}

.yb-cards__item--default .yb-card-chip::after {
  background: color-mix(in srgb, var(--yb-on-primary) 55%, transparent);
}

.yb-cards__text {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
}

.yb-cards__label {
  font-weight: var(--yb-weight-medium);
}

.yb-cards__expiry {
  color: var(--yb-text-muted);
  font-size: var(--yb-text-caption);
}

.yb-cards__expiry--expired {
  color: var(--yb-error);
}

.yb-cards-empty {
  display: flex;
  align-items: flex-start;
  gap: var(--yb-space-5);
  padding: var(--yb-space-6) var(--yb-space-5);
}

.yb-cards-empty__art {
  flex: none;
  padding-top: 2px;
}

.yb-cards-empty__card {
  display: block;
  width: 64px;
  height: 44px;
  border: 2px dashed var(--yb-border-strong);
  border-radius: 7px;
  background: radial-gradient(circle, var(--yb-border-strong) var(--yb-perforation-dot), transparent calc(var(--yb-perforation-dot) + 0.5px)) 0 70% / var(--yb-perforation-gap) 8px repeat-x;
}

.yb-cards-empty__text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--yb-space-2);
  max-width: 60ch;
}

.yb-cards-empty__title {
  font-weight: var(--yb-weight-strong);
}

.yb-cards-empty__text p:not(.yb-cards-empty__title) {
  color: var(--yb-text-muted);
}

.yb-cards-empty__text .mud-button-root {
  margin-top: var(--yb-space-2);
}

.yb-cards-empty__owner {
  font-size: var(--yb-text-caption);
}

.yb-billing-secure {
  display: flex;
  align-items: center;
  gap: var(--yb-space-2);
  padding: var(--yb-space-3) var(--yb-space-5);
  border-top: 1px solid var(--yb-border);
  color: var(--yb-text-muted);
  font-size: var(--yb-text-caption);
  line-height: var(--yb-leading-caption);
}

.yb-billing-secure .mud-icon-root {
  flex: none;
  font-size: 16px;
}

.yb-billing-empty {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--yb-space-3);
  padding: var(--yb-space-5);
  color: var(--yb-text-muted);
}

.yb-billing-empty > .mud-icon-root {
  flex: none;
  color: var(--yb-text-muted);
}

.yb-billing-empty p {
  flex: 1 1 260px;
}

/* ---------- History ---------- */
.yb-billing-history {
  container-type: inline-size;
}

.yb-billing-table {
  width: 100%;
  border-collapse: collapse;
}

.yb-billing-table thead th {
  height: var(--yb-row-head-height);
  padding: 0 var(--yb-space-3);
  border-bottom: 1px solid var(--yb-border);
  background: var(--yb-bg-sunken);
  color: var(--yb-text-muted);
  font-size: var(--yb-text-caption);
  font-weight: var(--yb-weight-medium);
  text-align: left;
  white-space: nowrap;
}

.yb-billing-table tbody th,
.yb-billing-table tbody td {
  height: var(--yb-row-height);
  padding: var(--yb-space-2) var(--yb-space-3);
  border-bottom: 1px solid var(--yb-border);
  vertical-align: middle;
}

/* After the cell padding (which reset it): the month lines up with its header and the card's edge. */
.yb-billing-table thead th:first-child,
.yb-billing-table tbody th {
  padding-left: var(--yb-space-5);
}

.yb-billing-table thead th:last-child,
.yb-billing-table tbody td:last-child {
  padding-right: var(--yb-space-5);
}

.yb-billing-table tbody tr:last-child > * {
  border-bottom: 0;
}

.yb-billing-table__month {
  font-weight: var(--yb-weight-medium);
  text-align: left;
  white-space: nowrap;
}

.yb-billing-table .yb-billing-table__num {
  text-align: right;
}

.yb-billing-table__free {
  color: var(--yb-text-muted);
}

.yb-billing-table__status {
  white-space: nowrap;
}

.yb-billing-table__hint {
  display: block;
  margin-top: 2px;
  color: var(--yb-text-muted);
  font-size: var(--yb-text-caption);
}

.yb-billing-table__actions {
  text-align: right;
  white-space: nowrap;
}

.yb-billing-table__actions > * + * {
  margin-left: var(--yb-space-3);
}

.yb-billing-table__row--unpaid > * {
  background: color-mix(in srgb, var(--yb-warning-soft) 45%, transparent);
}

.yb-billing-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 32px;
  color: var(--yb-primary);
  font-size: var(--yb-text-caption);
  font-weight: var(--yb-weight-medium);
  text-decoration: none;
  vertical-align: middle;
}

.yb-billing-link:hover {
  text-decoration: underline;
}

/* D406: « PDF » opens the application's window: a button that looks like the links next to it. */
button.yb-billing-link {
  padding: 0;
  border: 0;
  background: none;
  font-family: inherit;
  cursor: pointer;
}

button.yb-billing-link:focus-visible {
  outline: 2px solid var(--yb-focus, var(--yb-primary));
  outline-offset: 2px;
  border-radius: 4px;
}

.yb-billing-link .mud-icon-root {
  font-size: 16px;
}

/* Narrow: each month becomes a card (month and amount, then status, then documents). */
@container (max-width: 560px) {
  .yb-billing-table,
  .yb-billing-table tbody,
  .yb-billing-table tr,
  .yb-billing-table th,
  .yb-billing-table td {
    display: block;
  }

  .yb-billing-table thead {
    display: none;
  }

  .yb-billing-table tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 2px var(--yb-space-3);
    padding: var(--yb-space-3) var(--yb-space-5);
    border-bottom: 1px solid var(--yb-border);
  }

  .yb-billing-table tbody tr:last-child {
    border-bottom: 0;
  }

  .yb-billing-table tbody th,
  .yb-billing-table tbody td {
    height: auto;
    padding: 0;
    border: 0;
  }

  .yb-billing-table tbody th,
  .yb-billing-table tbody td:last-child {
    padding-left: 0;
    padding-right: 0;
  }

  .yb-billing-table__row--unpaid > * {
    background: none;
  }

  .yb-billing-table__row--unpaid {
    background: color-mix(in srgb, var(--yb-warning-soft) 45%, transparent);
  }

  /* Invoices: a caption under the month. */
  .yb-billing-table tbody td:nth-of-type(1) {
    grid-column: 1;
    grid-row: 2;
    color: var(--yb-text-muted);
    font-size: var(--yb-text-caption);
    text-align: left;
  }

  .yb-billing-table tbody td:nth-of-type(1)::before {
    content: attr(data-label) " ";
  }

  .yb-billing-table tbody td:nth-of-type(2) {
    grid-column: 2;
    grid-row: 1;
  }

  .yb-billing-table__status {
    grid-column: 2;
    grid-row: 2;
    text-align: right;
  }

  .yb-billing-table__actions {
    grid-column: 1 / -1;
    margin-top: var(--yb-space-2);
    text-align: left;
    white-space: normal;
  }
}

/* ---------- What counts ---------- */
.yb-billing-rules {
  margin: 0;
}

.yb-billing-rules > div {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: var(--yb-space-1) var(--yb-space-5);
  padding: var(--yb-space-3) 0;
}

.yb-billing-rules > div + div {
  border-top: 1px solid var(--yb-border);
}

.yb-billing-rules > div:first-child {
  padding-top: 0;
}

.yb-billing-rules > div:last-child {
  padding-bottom: 0;
}

.yb-billing-rules dt {
  font-weight: var(--yb-weight-medium);
}

.yb-billing-rules dd {
  margin: 0;
  max-width: 64ch;
  color: var(--yb-text-muted);
}

.yb-billing-rules-host {
  container-type: inline-size;
}

@container (max-width: 560px) {
  .yb-billing-rules > div {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1023px) {
  .yb-billing-alert__actions {
    flex-basis: 100%;
  }
}

@media (max-width: 767px) {
  .yb-billing-alert__actions {
    margin-left: 0;
  }

  .yb-cards-empty {
    flex-direction: column;
    gap: var(--yb-space-4);
  }
}

/* ---------- Card dialog ---------- */
.yb-card-dialog {
  display: flex;
  flex-direction: column;
  gap: var(--yb-space-4);
}

.yb-card-dialog__intro {
  color: var(--yb-text-muted);
}

.yb-card-dialog__element {
  position: relative;
  min-height: 120px;
}

.yb-card-dialog__loading {
  display: flex;
  flex-direction: column;
  gap: var(--yb-space-3);
}

.yb-card-dialog__error {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--yb-space-2);
  padding: var(--yb-space-3);
  border-radius: var(--yb-radius-sm);
  background: var(--yb-error-soft);
  color: var(--yb-error);
}

.yb-card-dialog__error p {
  flex: 1 1 240px;
  color: var(--yb-text);
}

.yb-card-dialog__message {
  color: var(--yb-error);
  font-weight: var(--yb-weight-medium);
}

.yb-card-dialog__secure {
  display: flex;
  align-items: center;
  gap: var(--yb-space-2);
  color: var(--yb-text-muted);
  font-size: var(--yb-text-caption);
  line-height: var(--yb-leading-caption);
}

.yb-card-dialog__secure .mud-icon-root {
  flex: none;
  font-size: 16px;
}

.yb-test-cards {
  display: flex;
  flex-direction: column;
  gap: var(--yb-space-2);
  margin: 0;
  padding: 0;
  border: 0;
}

.yb-test-card {
  display: grid;
  grid-template-columns: auto minmax(84px, auto) minmax(0, 1fr);
  grid-template-areas: "radio brand number" "radio effect effect";
  align-items: center;
  gap: 2px var(--yb-space-3);
  min-height: 52px;
  padding: var(--yb-space-2) var(--yb-space-3);
  border: 1px solid var(--yb-border);
  border-radius: var(--yb-radius-sm);
  cursor: pointer;
}

.yb-test-card:hover {
  background: var(--yb-hover);
}

.yb-test-card:focus-within {
  outline: 2px solid var(--yb-focus);
  outline-offset: 2px;
}

.yb-test-card--selected {
  border-color: var(--yb-primary);
  background: var(--yb-selected);
}

.yb-test-card input {
  grid-area: radio;
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--yb-primary);
}

.yb-test-card__brand {
  grid-area: brand;
  font-weight: var(--yb-weight-medium);
}

.yb-test-card__number {
  grid-area: number;
  white-space: nowrap;
}

.yb-test-card__effect {
  grid-area: effect;
  color: var(--yb-text-muted);
  font-size: var(--yb-text-caption);
}

@media (max-width: 479px) {
  .yb-test-card {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas: "radio brand" "radio number" "radio effect";
  }
}

/* ---------- Shell banner ---------- */
.yb-banner--blocked {
  border-color: color-mix(in srgb, var(--yb-error) 45%, transparent);
  background: var(--yb-error-soft);
  color: var(--yb-text);
}

.yb-banner--blocked .yb-banner__icon {
  color: var(--yb-error);
}

.yb-banner + .yb-banner {
  margin-top: var(--yb-space-2);
}

@media (prefers-reduced-motion: reduce) {
  .yb-usage__fill,
  .yb-usage__thumb {
    transition: none;
  }
}
