/**
 * ModalBilling.css
 * Styles for the combined plan and credits modal
 */

/* --- Layout --- */
/* Content inherits flex layout from .modal-part-content */

/* The credits modal's vertical rhythm. .modal-part-content is a flex column
   with no gap of its own, so without this the intro, tabs, cards and footer
   butt against each other. --space-3 between sections, --space-2 inside a
   card: the same two steps the rest of the modal furniture uses. */
.billing-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.billing-content hr {
  border: none;
  border-top: var(--border-width) var(--border-style) var(--color-border);
  margin: var(--space-2) 0;
}

/* Fine print, at the foot of the content and level with the summary in the
   button row below it. The one place --font-size-sm earns its keep: it is
   the only text here that is genuinely subordinate to everything else. */
.billing-hints {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: auto;
  color: var(--color-text-dark);
  font-size: var(--font-size-sm);
}

/* --- Credits: one card per credit type, its size ladder inside --- */

/* Group switch (Plan / Chat / Media): the shared .tabs, joined to the
   panel below that holds the intro and the cards. The cards inside step
   down to the page ground so they still read as cards on the panel's
   surface. */
.billing-tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}

.billing-panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--color-surface);
  border: var(--border-width) var(--border-style) var(--color-border);
  border-radius: var(--radius-lg);
}

.billing-panel .billing-card {
  background: var(--color-background);
}

.billing-intro {
  color: var(--color-text-dark);
}

.billing-spark {
  color: var(--color-accent-text);
}

/* auto-fit rather than a fixed count: Chat shows three cards and Media four,
   and the same rule collapses both to one column in a narrow modal.
   The 300px track is measured, not guessed -- the widest rung (a pack label,
   its savings line, a price and an open stepper) needs 288px inside the
   card's padding. Cards wrap to a new row before their content ever does. */
.billing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--space-3);
  align-content: start;
}

/* A class's own `display` outranks the UA [hidden] rule, so every panel that
   sets one has to say this or it stays on screen when its tab is inactive. */
.billing-grid[hidden],
.billing-hints[hidden] {
  display: none;
}

.billing-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3);
  /* The last row inside a card carries its own --space-2 of bottom padding,
     which would otherwise stack on the card's and leave the foot looking
     deeper than the head. Taking that much off here keeps the inset even on
     all four edges. */
  padding-bottom: var(--space-1);
  background: var(--color-surface);
  border: var(--border-width) var(--border-style) var(--color-border);
  border-radius: var(--radius-lg);
}

/* Plan cards are chosen by clicking the card itself; credit cards are chosen
   by their rungs. */
.billing-card-pick {
  cursor: pointer;
}

/* The accent variant with readable contrast on this theme's surfaces -- it
   resolves to accent-light in dark and accent-dark in light. */
.billing-card-tag {
  color: var(--color-accent-text);
}

/* Whatever is chosen on this tab -- or, before anything is, the type the
   caller ran out of. */
.billing-card-focus {
  border-color: var(--color-accent);
}

.billing-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
}

.billing-card-name {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  white-space: nowrap;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-bold);
}

.billing-card-note {
  color: var(--color-text-dark);
  white-space: nowrap;
}

.billing-card-note-empty {
  color: var(--color-error);
}

.billing-card-blurb {
  color: var(--color-text-dark);
  white-space: nowrap;
}

/* The rows inside a card: a plan's allowances, or a type's size ladder.
   Hairlines between them rather than a box around each -- three levels of
   nested boxes (modal > card > row) is what read as noise. */
.billing-lines {
  display: flex;
  flex-direction: column;
}

.billing-line {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--height-input);
  padding: var(--space-2) var(--space-1);
}

.billing-rung + .billing-rung {
  border-top: var(--border-width) var(--border-style) var(--color-border);
}

.billing-line-label {
  flex: 1;
  min-width: 0;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  white-space: nowrap;
}

.billing-line-label svg {
  flex-shrink: 0;
  color: var(--color-text-dark);
}

/* A plan's two columns of allowances, and the permissions that run under
   both of them. */
.billing-card-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-2);
}

/* The rule between the columns, with matching air either side of it (the
   grid gap on the left, the column's own padding on the right). */
.billing-card-columns > .billing-lines + .billing-lines {
  padding-left: var(--space-2);
  border-left: var(--border-width) var(--border-style) var(--color-border);
}

.billing-column-head {
  padding: var(--space-1);
  border-bottom: var(--border-width) var(--border-style) var(--color-border);
  color: var(--color-text-dark);
}

/* Permissions sit under both columns, and beside each other -- so the pair
   reads as one row rather than a second stack. */
.billing-lines-span {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
  border-top: var(--border-width) var(--border-style) var(--color-border);
}

/* A ladder rung is a line you can click. */
.billing-rung {
  cursor: pointer;
}

.billing-rung:focus-visible {
  outline: var(--focus-outline);
}

/* Nothing inside a card wraps: the grid drops a column and the cards get
   wider instead (see the min track on .billing-grid). A wrapped
   "150 Messages" over two lines is what made the rungs read as clutter. */
.billing-rung-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  white-space: nowrap;
}

/* What the rung saves, under its title rather than trailing it. */
.billing-rung-meta {
  font-size: var(--font-size-sm);
  color: var(--color-text-dark);
}

.billing-rung-price {
  white-space: nowrap;
}

/* A rung at rest shows only its + . The minus and the count appear once it
   holds something, so a ladder of twelve reads as twelve prices rather than
   twelve spin boxes. */
.billing-rung-qty {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.billing-rung[data-qty='0'] .billing-rung-dec,
.billing-rung[data-qty='0'] .billing-rung-value {
  display: none;
}

.billing-rung[data-qty='0'] .billing-rung-inc {
  border-radius: var(--radius-sm);
}

/* --- Footer: what you end up with, and how many of it --- */
/* The running summary sits in the modal's own button row, left of the
   buttons that act on it. */
.billing-summary {
  flex: 1;
  min-width: 0;
  text-align: left;
  color: var(--color-text-dark);
}

/* --- Spin box --- */
.billing-spinner {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.billing-spinner-btn {
  width: 24px;
  height: 24px;
  border: var(--border-width) var(--border-style) var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size);
  padding: 0;
  transition: background 0.15s;
}

:where(html[data-pointer='mouse']) .billing-spinner-btn:hover:not(:disabled) {
  background: var(--color-surface-light);
}

.billing-spinner-btn:disabled {
  color: var(--color-text-dark);
  cursor: default;
}

.billing-spinner-value {
  width: 28px;
  text-align: center;
  border-top: var(--border-width) var(--border-style) var(--color-border);
  border-bottom: var(--border-width) var(--border-style) var(--color-border);
  height: 24px;
  line-height: 24px;
}

/* --- Responsive (container-based for the resizable modal) --- */

/* The grid's own auto-fit track handles the column count on every tab, so all
   that is left here is touch sizing once the cards have stacked. */
@container (max-width: 615px) {
  .billing-line,
  .billing-tab,
  .billing-spinner-btn,
  .billing-spinner-value {
    min-height: 44px;
  }

  .billing-spinner-btn {
    width: 44px;
  }

  .billing-spinner-value {
    width: 40px;
    line-height: 44px;
  }

  .modal-part-buttons {
    flex-wrap: wrap;
  }

  .billing-summary {
    flex: 1 0 100%;
  }
}
