/* Scribe — plans, usage and upgrade prompts.
 *
 * Loaded after styles.css and built only from its tokens, so the meter,
 * banners and dialogs read as part of the same page rather than a widget
 * dropped on top of it. Everything here is created by billing.js. */

/* ---- Usage meter: the plan row at the foot of the sidebar --------------- */

/* "Free · 1 of 2 left" with Upgrade (or Plans) beside it, and a 3px bar under
   both. billing.js puts the plan's name, the words and the bar inside
   .billing-meter-info (the readout, which opens the plans) and .billing-gauge;
   those two step aside (display: contents) so their pieces line up in the
   meter's own grid, and a click on any piece still reaches the readout. */
#billingSlot:empty { display: none; }
.billing-meter { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; column-gap: 4px; margin-bottom: 10px; }
.billing-meter-info, .billing-gauge { display: contents; }
/* The plan's name is a pill elsewhere; here it is the start of the line. */
.billing-meter .billing-plan { grid-area: 1 / 1; padding: 0; border-radius: 0; background: none; color: var(--muted); font-weight: 400; }
.billing-plan::after { content: " ·"; }
.billing-plan, .billing-gauge-label { font-size: 11px; line-height: 1.4; white-space: nowrap; cursor: pointer; }
.billing-gauge-label { grid-area: 1 / 2; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.billing-meter-action { grid-area: 1 / 3; margin-left: 6px; padding: 4px 10px; border-radius: 7px; font-size: 11px; white-space: nowrap; }
.billing-meter-action.billing-link { padding: 4px 2px; }
.billing-bar { grid-area: 2 / 1 / 3 / 4; display: block; height: 3px; margin-top: 8px; border-radius: 8px; background: var(--track); overflow: hidden; }
.billing-bar-fill { display: block; height: 100%; width: 0; background: var(--green); border-radius: inherit; transition: width .3s ease; }
.billing-meter.warn .billing-bar-fill { background: var(--accent); }
.billing-meter.warn .billing-gauge-label { color: var(--accent); }

/* A button that reads as a link: "Plans", "Manage billing". */
.billing-link { border: 0; background: transparent; padding: 4px 0; color: var(--accent); font-size: 12px; font-weight: 550; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.billing-link:hover:not(:disabled) { background: transparent; color: var(--accent-strong); }

/* Other billing buttons wait while one action is in flight. */
[data-billing-action][aria-disabled="true"] { opacity: .5; cursor: progress; }
[data-billing-action][aria-busy="true"] { opacity: .8; }

/* ---- Banners, at the top of the main column ----------------------------- */

.billing-banners:empty { display: none; }
.billing-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px; padding: 10px 36px; border-bottom: 1px solid var(--line); background: var(--neutral-soft); font-size: 12px; }
.billing-banner-mark { width: 7px; height: 7px; flex-shrink: 0; border-radius: 50%; background: var(--faint); }
.billing-banner-copy { flex: 1 1 260px; min-width: 0; margin: 0; overflow-wrap: anywhere; }
.billing-banner-copy strong { font-weight: 600; }
.billing-banner-copy span { color: var(--muted); }
.billing-banner-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.billing-banner-actions button { font-size: 11px; padding: 6px 12px; }
.billing-banner-actions .ghost { background: var(--panel); }
.billing-dismiss { border: 0; background: transparent; color: var(--muted); font-size: 17px; line-height: 1; padding: 4px 7px; }
.billing-dismiss:hover:not(:disabled) { background: var(--wash); }
.billing-banner.bad { background: var(--danger-bg); border-bottom-color: var(--danger-line); }
.billing-banner.bad .billing-banner-mark { background: var(--accent); }
.billing-banner.bad strong { color: var(--danger-text); }
.billing-banner.accent { background: var(--accent-soft); border-bottom-color: var(--accent-line); }
.billing-banner.accent .billing-banner-mark { background: var(--accent); }
.billing-banner.good { background: var(--green-soft); border-bottom-color: var(--green-line); }
.billing-banner.good .billing-banner-mark { background: var(--green); }
.billing-banner.good strong { color: var(--green); }

/* ---- Dialogs ------------------------------------------------------------ */

/* Lock the page behind an open dialog without the scrollbar's width jumping. */
html:has(.billing-dialog[open]) { overflow: hidden; scrollbar-gutter: stable; }
.billing-dialog { width: min(860px, calc(100vw - 32px)); max-width: none; max-height: calc(100dvh - 32px); padding: 0; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); box-shadow: 0 24px 70px var(--shadow), 0 2px 8px var(--shadow-soft); }
.billing-dialog::backdrop { background: var(--overlay); }
.billing-dialog-body { max-height: calc(100dvh - 34px); overflow-y: auto; overscroll-behavior: contain; padding: 30px; }
.billing-dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.billing-dialog h2 { font: 32px/1.1 Georgia, "Times New Roman", serif; letter-spacing: -1px; margin: 10px 0 0; }
.billing-dialog h2 span { color: var(--accent); }
.billing-close { flex-shrink: 0; border: 0; background: transparent; color: var(--muted); font-size: 22px; line-height: 1; padding: 6px 10px; margin: -8px -12px 0 0; }
.billing-standing { color: var(--muted); font-size: 12px; margin: 10px 0 0; }
.billing-notice { margin: 16px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--neutral-soft); color: var(--muted); font-size: 12px; }

.billing-cards { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; margin-top: 24px; }
.billing-card { display: flex; flex-direction: column; min-width: 0; padding: 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.billing-card.recommended { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.billing-card.current { background: var(--sunken); }
.billing-card-top { display: flex; align-items: center; height: 16px; }
.billing-popular { color: var(--accent); }
.billing-yours { color: var(--green); }
.billing-card h3, .billing-offer h3 { font: 22px/1.2 Georgia, "Times New Roman", serif; letter-spacing: -.4px; margin: 6px 0 2px; }
.billing-price { display: flex; align-items: baseline; gap: 5px; margin: 0; }
.billing-price strong { font: 400 30px/1.2 Georgia, "Times New Roman", serif; letter-spacing: -1px; }
.billing-price span { color: var(--muted); font-size: 12px; }
/* "$89.99 billed yearly · save 25%", or "Billed monthly". */
.billing-price-note { margin: 0; color: var(--muted); font-size: 11px; }

/* Monthly | Yearly: two buttons on a sunken track, the pressed one raised
   like the card around it. Drawn from the page's tokens alone, so it follows
   the theme; the one shadow is the same translucent ink the dialog casts. */
.billing-interval { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 2px; margin: 10px 0 12px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.billing-interval button { min-width: 0; padding: 6px 8px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 550; line-height: 1.35; }
.billing-interval button:hover:not(:disabled) { background: transparent; color: var(--text); }
.billing-interval button[aria-pressed="true"], .billing-interval button[aria-pressed="true"]:hover:not(:disabled) { background: var(--panel); color: var(--text); box-shadow: 0 0 0 1px var(--line), 0 1px 3px var(--shadow-mid); cursor: default; }
/* Inside the track, where 4px out would be clipped by its neighbour. */
.billing-interval button:focus-visible { outline-offset: 1px; }
.billing-save { color: var(--green); }
.billing-summary { color: var(--muted); font-size: 12px; margin: 6px 0 16px; }
.billing-features { display: grid; gap: 8px; list-style: none; margin: 0 0 22px; padding: 14px 0 0; border-top: 1px solid var(--line); font-size: 12px; }
.billing-features li { display: flex; gap: 8px; }
.billing-features li::before { content: "✓"; flex-shrink: 0; color: var(--green); font-size: 11px; }
.billing-card-action { display: grid; gap: 8px; margin-top: auto; }
.billing-card-action > button, .billing-limit-primary > button { width: 100%; font-size: 12px; }
.billing-here { margin: 0; padding: 9px 12px; border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); font-size: 11px; text-align: center; }
.billing-note { margin: 0; color: var(--muted); font-size: 11px; text-align: center; }
.billing-error { margin: 0; color: var(--danger-text); font-size: 11px; overflow-wrap: anywhere; }
.billing-confirm { display: grid; gap: 10px; padding: 12px; border-radius: 10px; background: var(--accent-soft); font-size: 12px; }
.billing-confirm p { margin: 0; }
.billing-confirm-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.billing-confirm-actions button { flex: 1 1 auto; font-size: 12px; padding: 8px 12px; }
.billing-confirm-actions .ghost { background: var(--panel); }

.billing-dialog-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 24px; margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); }
.billing-dialog-foot .small-note { margin: 0; max-width: 540px; }
.billing-manage { display: grid; gap: 4px; justify-items: end; }

/* The limit dialog: narrower, one plan on offer. */
.billing-dialog.billing-limit { width: min(440px, calc(100vw - 32px)); }
.billing-limit .billing-dialog-body { padding: 26px 28px 28px; }
.billing-limit .billing-dialog-head { align-items: center; }
.billing-limit h2 { font-size: 25px; letter-spacing: -.6px; margin: 12px 0 0; }
.billing-lead { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.billing-offer { margin-top: 20px; padding: 16px 18px; border: 1px solid var(--accent); border-radius: 12px; box-shadow: inset 0 0 0 1px var(--accent); }
.billing-offer-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.billing-offer h3 { margin: 0; }
.billing-offer .billing-price strong { font-size: 24px; }
/* Under the price, which sits at the right of the name. */
.billing-offer > .billing-price-note { text-align: right; }
.billing-offer .billing-summary { margin: 2px 0 12px; }
.billing-offer .billing-features { margin: 0; padding-top: 12px; }
.billing-limit-actions { display: grid; gap: 8px; margin-top: 20px; }
.billing-limit-primary { display: grid; gap: 8px; }
.billing-limit-secondary { display: flex; gap: 8px; }
.billing-limit-secondary button { flex: 1; font-size: 12px; }

.billing-toast { z-index: 60; }

/* Free and Plus side by side, each a column of the same width. */
.billing-dialog.billing-plans { width: min(720px, calc(100vw - 32px)); }
@media (min-width: 760px) {
  .billing-plans .billing-cards { grid-template-columns: none; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: no-preference) {
  .billing-dialog[open] { animation: billing-rise .18s ease-out; }
  .billing-dialog[open]::backdrop { animation: billing-fade .18s ease-out; }
  .billing-banner { animation: billing-fade .2s ease-out; }
}
@keyframes billing-rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes billing-fade { from { opacity: 0; } }

@media (max-width: 740px) {
  .billing-banner { padding: 10px 20px; }
  .billing-dialog-body { padding: 22px 18px; }
  .billing-dialog h2 { font-size: 26px; }
  .billing-limit .billing-dialog-body { padding: 22px 18px; }
  .billing-dialog-foot { flex-direction: column; align-items: stretch; }
  .billing-manage { justify-items: start; }
}
