/* Billing page — extends dashboard shell */

:root {
  --bill-purple: var(--color-cosmos-accent);
  --bill-plan-cosmos-deep: var(--color-cosmos-deep);
  --bill-plan-cosmos-mid: var(--color-cosmos-stellar);
  --bill-plan-cosmos-light: var(--color-cosmos-mist);
  --bill-purple-soft: var(--dash-surface-hover);
  --bill-card-elevated: var(--dash-elevated);
  --bill-border: var(--color-border-secondary);
  --bill-text: var(--dash-text, #f4f4f5);
  --bill-danger: var(--color-error);
  --bill-danger-soft: var(--color-error-soft);
  --bill-right-w: 376px;
}

body.bill-page {
  --dash-purple: var(--bill-purple);
  --dash-purple-soft: var(--bill-purple-soft);
}

.bill-page .dash-new-btn {
  background: var(--bill-purple);
}

.bill-page .dash-pro__btn {
  background: var(--bill-purple);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.bill-page .dash-search input:focus {
  border-color: var(--dash-border-strong);
  box-shadow: 0 0 0 3px var(--dash-surface-hover);
}

.bill-content {
  padding: var(--dash-content-y, 32px) var(--dash-page-x, 32px);
  padding-left: calc(var(--dash-page-x, 32px) + var(--dash-mobile-nav-gutter, 0px));
  padding-bottom: calc(var(--dash-content-y, 32px) + var(--dash-content-pad-bottom, 0px));
  flex: 1;
  min-width: 0;
  container: bill-content / inline-size;
}

.bill-stack {
  display: flex;
  flex-direction: column;
  gap: var(--dash-island-gap, 16px);
  min-width: 0;
}

.bill-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(18rem, var(--bill-right-w));
  gap: var(--dash-gap, 24px);
  align-items: start;
}

.bill-main {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

/* Invoices: the DS table island; the status column stays narrow as in the DS module. */
.bill-invoices .bill-invoices__status {
  width: 7.5rem;
}

.bill-aside {
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: sticky;
  top: var(--dash-gap, 24px);
  min-width: 0;
  margin-top: 0;
}

/* Shared card */
.bill-card {
  background: var(--dash-page-island-bg, var(--dash-card));
  border: 0;
  border-radius: 28px;
  padding: 24px;
  box-shadow: none;
  transition: background 150ms ease;
}

.bill-card__title {
  margin: 0 0 16px;
  font-size: calc(16px + var(--nv-island-title-increase, 0px));
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.25;
  color: var(--bill-text);
}

.bill-panel[hidden],
.bill-card[hidden],
.bill-badge[hidden],
.bill-btn[hidden] {
  display: none !important;
}

/* Badges */
.bill-badge {
  display: inline-flex;
  align-items: center;
  height: 22px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.bill-badge--muted {
  background: var(--color-well-hover);
  color: var(--dash-text-muted);
}

/* Right panel */
.bill-panel {
  background: var(--dash-page-island-bg, var(--dash-card));
  border: 0;
  border-radius: 28px;
  padding: 24px;
  box-shadow: none;
  transition: background 150ms ease;
}

.bill-panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
}

.bill-panel__title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.25;
  color: var(--bill-text);
}

.bill-panel__meta {
  font-size: 12px;
  color: var(--dash-text-muted);
}

/* Usage */
.bill-usage {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.bill-btn {
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  border: none;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background 150ms ease, color 150ms ease;
}

.bill-btn--primary {
  background: var(--bill-purple);
  color: var(--dash-accent-text, #0a0a0a);
}

.bill-btn--primary:hover {
  background: color-mix(in srgb, var(--bill-purple) 90%, white);
}

.bill-btn--secondary {
  background: var(--color-well);
  color: var(--bill-text);
}

.bill-btn--secondary:hover {
  background: var(--color-well-hover);
}

.bill-btn--danger {
  background: var(--bill-danger-soft);
  border: none;
  color: var(--bill-danger);
}

.bill-btn--danger:hover {
  background: color-mix(in srgb, var(--bill-danger) 20%, transparent);
}

.bill-btn--block {
  width: 100%;
}

.bill-btn:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

/* Dialogs */
.bill-dialog {
  color-scheme: inherit;
  box-sizing: border-box;
  width: min(440px, calc(100vw - 32px));
  max-height: min(42rem, calc(100dvh - 32px));
  margin: auto;
  padding: 0;
  overflow: auto;
  border: var(--dash-island-border);
  border-radius: var(--dash-radius-card, 20px);
  background: var(--dash-card);
  color: var(--bill-text);
  box-shadow: var(--shadow-xl, 0 24px 80px rgba(0, 0, 0, 0.4));
}

html:not(.light):not(.light-theme) .bill-dialog {
  border: none;
}

.bill-dialog::backdrop {
  background: var(--color-overlay);
  backdrop-filter: blur(8px);
}

.bill-dialog__panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
}

.bill-dialog__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.bill-dialog__head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0;
  line-height: 1.25;
  color: var(--bill-text);
}

.bill-dialog__close {
  display: grid;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--color-well);
  color: var(--dash-text-muted);
  cursor: pointer;
  padding: 0;
}

.bill-dialog__close:hover {
  background: var(--color-well-hover);
  color: var(--bill-text);
}

.bill-dialog__close:focus-visible,
.bill-btn:focus-visible {
  outline: 2px solid var(--dash-accent-focus);
  outline-offset: 2px;
}

.bill-dialog .set-btn--ghost,
.bill-dialog .bill-btn--secondary {
  background: var(--color-well);
  color: var(--bill-text);
}

.bill-dialog__copy {
  margin: 0;
  color: var(--dash-text-muted);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
}

.bill-dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.bill-toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: var(--z-tooltip, 80);
  max-width: min(340px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 999px;
  background: var(--dash-popover-bg-solid, var(--dash-card));
  color: var(--bill-text);
  box-shadow: var(--dash-popover-shadow, var(--shadow-xl));
  font-size: 14px;
  font-weight: 500;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.bill-toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@container bill-content (max-width: 900px) {
  .bill-layout {
    grid-template-columns: 1fr;
  }

  .bill-aside {
    position: static;
    margin-top: 0;
  }
}

@media (max-width: 800px) {
  .bill-content {
    padding-right: var(--dash-page-x, 20px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .bill-dialog::backdrop {
    backdrop-filter: none;
  }
}

/* Plan: the current plan in one island at the top of the main column; the grid to change it lives on Plans. */
.bill-plans__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.bill-plans__head .bill-card__title {
  margin: 0;
}

.bill-current__name {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 12px;
  margin: 16px 0 0;
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
  color: var(--bill-text);
}

.bill-current__price {
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--dash-text-muted);
  font-variant-numeric: tabular-nums;
}

.bill-plans__note {
  margin: 6px 0 0;
  min-height: 20px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--dash-text-muted);
}

/* A scheduled change or an unpaid upgrade: a line and its action inside the Plan island, no surface of its own. */
.bill-current__scheduled {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 16px;
}

.bill-current__scheduled[hidden] {
  display: none;
}

/* The payment note. */
.bill-panel__copy {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--dash-text-muted);
}

.bill-panel__copy + .bill-btn {
  margin-top: 16px;
}

/* Until the server answers (billing.js removes data-bill-loading): tiles and lines as placeholders, never a guessed
   plan that flips to another one. */
[data-bill-loading] :is(.bill-plans__note, .bill-current__name) {
  animation: bill-skeleton-pulse 1.6s ease-in-out infinite;
}

[data-bill-loading] :is(.bill-plans__note, .bill-current__name) {
  width: 14rem;
  border-radius: 6px;
  color: transparent;
  background: color-mix(in srgb, var(--dash-text, #f4f4f5) 6%, transparent);
}

[data-bill-loading] [data-bill-history] {
  visibility: hidden;
}

@keyframes bill-skeleton-pulse {
  50% { opacity: 0.55; }
}

@media (prefers-reduced-motion: reduce) {
  [data-bill-loading] * {
    animation: none;
  }
}
