/* ============================================================
   BibTeX generator chunk

   Reused globals (no CSS here):
     - .hero / .hero-grid-bg / .hero-aurora / .hero-badge / .hero-tag /
       .hero-sub / .hero h1 / .hero__stack
     - .btn / .btn--primary / .btn--outline / .btn--lg / .btn--sm
     - .delivery-tier (with --orange / --green / --purple modifiers)
     - .delivery-section
     - .features-grid / --2col
     - .faq-section / .faq-section__layout / .spotlight-cta
     - .cta-band / .code-card
     - .section / .divider / .divider-grid

   This chunk owns:
     .hero--bibtex            hero padding + stacking context
     .bibtex-widget           outer wrapper inside the hero
     .bibtex-form             form container
     .bibtex-input            textarea card + Show sample + Upload file
     .bibtex-controls         From + To pickers + Convert row
     .bibtex-pick(-wrap)      picker pill + position anchor
     .bibtex-pop              picker popover (grouped options)
     .bibtex-convert          primary submit button
     .bibtex-status           status line (drop-count notice only)
     .bibtex-result           result card (entry rows + actions + errors)
     .bibtex-lead             lead-gen CTA after first success
     .bibtex-tiers            stack wrapper for body delivery-tier cards
     .bibtex-tier--steps      mobile rule for the "How to" steps card
   ============================================================ */

/* ---- Hero adjustments for converter pages ---- */
.hero--bibtex {
  padding: 100px 0 0;
  /* Own stacking context so the picker popover (z-index inside)
     paints above the .divider-grid that sits after the hero in DOM. */
  position: relative;
  z-index: 5;
}
.hero--bibtex .hero-tag {
  font-size: clamp(.95rem, 1.6vw, 1.15rem);
  font-weight: 500;
}
.hero--bibtex .hero-sub { max-width: 720px; margin-bottom: 0; }
.hero--bibtex .hero-aurora__blob { filter: blur(60px); }
@media (max-width: 768px) {
  .hero--bibtex .hero-aurora__blob { filter: blur(40px); }
}

/* ---- Widget wrapper inside .hero ---- */
.bibtex-widget {
  position: relative;
  z-index: 1;
  padding: 40px 20px 88px;
  text-align: left;
}
.bibtex-widget__inner { max-width: 920px; margin: 0 auto; }

.bibtex-form {
  max-width: 920px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---- Input card ---- */
.bibtex-input {
  background: var(--color-bg);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
}
.bibtex-input__top {
  display: flex;
  justify-content: flex-end;
  padding: 10px 14px 0;
}
.bibtex-input__sample {
  background: transparent;
  border: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: .85rem;
  font-weight: 600;
  color: var(--color-accent);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.bibtex-input__sample:hover { color: var(--color-accent-hover); }

.bibtex-input__textarea {
  width: 100%;
  border: 0;
  outline: 0;
  padding: 12px 16px 16px;
  background: transparent;
  color: var(--color-text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .92rem;
  line-height: 1.55;
  resize: vertical;
  min-height: 120px;
}
.bibtex-input__textarea::placeholder {
  color: var(--color-text-muted);
  opacity: .75;
}
.bibtex-input__textarea:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
  border-radius: var(--radius-md);
}

.bibtex-input__bottom {
  display: none;
  padding: 0 14px 12px;
}
.bibtex-input--file .bibtex-input__bottom { display: block; }
.bibtex-input__upload {
  background: var(--color-bg-warm);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-family: var(--font-sans);
  font-size: .85rem;
  font-weight: 500;
  color: var(--color-text);
  cursor: pointer;
}
.bibtex-input__upload:hover { border-color: var(--color-accent); color: var(--color-accent); }
.bibtex-input__file { display: none; }

/* ---- Controls row (pickers + convert) ---- */
.bibtex-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

/* Wrapper makes the popover an absolutely-positioned sibling of the
   pill rather than a child (a <button> can't validly contain a
   listbox). */
.bibtex-pick-wrap {
  position: relative;
  display: inline-flex;
}

/* Picker pill — rectangle with rounded corners, light grey fill */
.bibtex-pick {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #FAFAFA;
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-family: var(--font-sans);
  font-size: .95rem;
  cursor: pointer;
  color: var(--color-text);
  transition: border-color .12s ease, background .12s ease;
  min-height: 44px;
}
.bibtex-pick:hover,
.bibtex-pick.is-open {
  border-color: var(--color-accent);
  background: var(--color-bg);
}
.bibtex-pick__label {
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}
.bibtex-pick__value { font-weight: 600; }
.bibtex-pick__caret {
  display: inline-flex;
  align-items: center;
  color: var(--color-text-muted);
  margin-left: 2px;
}
.bibtex-pick.is-open .bibtex-pick__caret { transform: rotate(180deg); }

/* Picker popover (anchored under the pill). Fully opaque white surface
   so the page's hero grid-dot pattern doesn't bleed through. */
.bibtex-pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  /* Wide enough that the longest label ("PubMed (.nbib)", "Legacy
     BibTeX") fits in its column without ellipsis. */
  min-width: 560px;
  max-width: min(640px, calc(100vw - 32px));
  background: #FFFFFF;
  opacity: 1;
  isolation: isolate;
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 36px rgba(20,20,19,.18);
  padding: 18px;
  z-index: 100;
}
.bibtex-pop__group-label {
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin: 12px 4px 8px;
}
.bibtex-pop__group-label:first-child,
.bibtex-pop > .bibtex-pop__group-label:nth-of-type(1) { margin-top: 4px; }
.bibtex-pop__group {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 10px;
}
.bibtex-pop__group:last-child { margin-bottom: 0; }
.bibtex-pop__item {
  background: #FAFAFA;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-family: var(--font-sans);
  font-size: .82rem;
  color: var(--color-text);
  text-align: center;
  cursor: pointer;
  /* No truncation: labels are short, popover is wide enough; if a
     single label is unusually long, allow a clean wrap. */
  white-space: normal;
  line-height: 1.2;
}
.bibtex-pop__item:hover,
.bibtex-pop__item:focus-visible {
  border-color: var(--color-accent);
  color: var(--color-accent);
  outline: none;
}
.bibtex-pop__item:focus-visible {
  box-shadow: 0 0 0 2px var(--color-accent-tint, rgba(0,0,0,.12));
}
.bibtex-pop__item.is-current {
  background: var(--color-accent-tint);
  border-color: var(--color-accent);
  color: var(--color-accent-strong);
  font-weight: 600;
}
@media (max-width: 900px) {
  /* Tablet: drop to 3 columns so labels still fit comfortably */
  .bibtex-pop__group { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 480px) {
  .bibtex-pop {
    min-width: calc(100vw - 48px);
    max-width: calc(100vw - 48px);
  }
  /* Mobile popover: 2 columns (4 across is too dense on phones) */
  .bibtex-pop__group { grid-template-columns: 1fr 1fr; }
  /* The TO pill is the 2nd .bibtex-pick-wrap in the controls row.
     Its popover anchored at `left: 0` would start mid-viewport and
     overflow off the right edge. Anchor it to the right edge instead
     so the popover spans the same area as the FROM popover does. */
  .bibtex-controls .bibtex-pick-wrap + .bibtex-pick-wrap .bibtex-pop {
    left: auto;
    right: 0;
  }
}

/* Convert button — pushed to the end of the controls row */
.bibtex-convert { margin-left: auto; }

@media (max-width: 640px) {
  /* Mobile: keep From + To pills side-by-side on one row, push
     Convert to its own full-width row underneath. */
  .bibtex-controls {
    flex-wrap: wrap;
  }
  .bibtex-pick-wrap { flex: 1 1 0; min-width: 0; }
  .bibtex-pick {
    width: 100%;
    justify-content: space-between;
  }
  .bibtex-convert {
    margin-left: 0;
    width: 100%;
    flex-basis: 100%;
  }
}

/* ---- Status line ---- */
.bibtex-status {
  font-size: .9rem;
  color: var(--color-text-muted);
  text-align: center;
  min-height: 1.4em;
}
.bibtex-status:empty { display: none; }

/* ---- Result panel ---- */
.bibtex-result {
  background: var(--color-bg);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.bibtex-result__row {
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border-subtle);
}
.bibtex-result__row:last-child { border-bottom: 0; }
.bibtex-result__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 14px;
  margin-bottom: 10px;
}
.bibtex-result__source {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .8rem;
  font-weight: 600;
  color: var(--color-accent-strong);
  background: var(--color-accent-tint);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  word-break: break-all;
}
.bibtex-result__type-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .82rem;
  color: var(--color-text-muted);
}
.bibtex-result__type-select {
  font-family: var(--font-sans);
  font-size: .84rem;
  padding: 3px 6px;
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  background: var(--color-bg);
  cursor: pointer;
}
.bibtex-result__copy {
  margin-left: auto;
  background: transparent;
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-sm);
  padding: 3px 12px;
  font-family: var(--font-sans);
  font-size: .82rem;
  font-weight: 600;
  color: var(--color-text);
  cursor: pointer;
}
.bibtex-result__copy:hover { border-color: var(--color-accent); color: var(--color-accent); }

/* Mobile: stack the per-row controls cleanly.
   Row 1: source chip (DOI / PMID / etc.) on its own line.
   Row 2: "Entry type:" label + the select, with the select stretching
          to fill the remaining width so it never overflows.
   Row 3: Copy button right-aligned. */
@media (max-width: 560px) {
  .bibtex-result__controls {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .bibtex-result__source { align-self: flex-start; }
  .bibtex-result__type-label {
    display: flex;
    width: 100%;
    gap: 8px;
  }
  .bibtex-result__type-label > span {
    white-space: nowrap;
    flex: 0 0 auto;
  }
  .bibtex-result__type-select {
    flex: 1 1 auto;
    min-width: 0;
  }
  .bibtex-result__copy {
    margin-left: 0;
    align-self: flex-end;
  }
}
.bibtex-result__body {
  margin: 0;
  padding: 10px 12px;
  background: var(--color-bg-subtle);
  border-radius: var(--radius-md);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  /* Smaller font: nobody actually reads BibTeX bodies — they copy
     them. Compact rendering lets a 5-record batch fit on one screen.
     11px is the smallest safe size that respects most browser
     minimum-font-size accessibility settings. */
  font-size: 11px;
  line-height: 1.4;
  color: var(--color-text);
  overflow-x: auto;
  white-space: pre-wrap;
  border: 1px solid var(--color-border-subtle);
}

/* Variant: result card containing only an errors panel (no successful
   entries above). Trims the actions-row border since there's no row
   above the errors panel. */
.bibtex-result--errors-only .bibtex-result__errors { border-top: 0; }

.bibtex-result__actions {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 12px 16px;
  border-top: 1px solid var(--color-border-subtle);
  background: var(--color-bg-sand);
}
/* Conversion summary ("4 of 5 converted") sits centered between the
   Copy all (left) and Download (right) buttons. */
.bibtex-result__summary {
  flex: 1;
  text-align: center;
  font-size: .88rem;
  color: var(--color-text-muted);
  font-weight: 500;
}

/* Error panel below the actions row — neutral muted styling, NOT red.
   Mirrors the way bibtex.com communicates partial-batch failures. */
.bibtex-result__errors {
  padding: 12px 16px 14px;
  border-top: 1px solid var(--color-border-subtle);
  background: var(--color-bg-subtle);
  font-size: .82rem;
  color: var(--color-text-muted);
}
.bibtex-result__errors-head {
  font-weight: 400;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}
.bibtex-result__errors-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  padding: 4px 0;
}
.bibtex-result__errors-source {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-weight: 400;
  color: var(--color-text);
  word-break: break-all;
}
.bibtex-result__errors-message { color: var(--color-text-muted); }

@media (max-width: 480px) {
  .bibtex-result__actions {
    flex-wrap: wrap;
  }
  .bibtex-result__summary {
    order: 3;
    flex-basis: 100%;
    text-align: center;
    padding-top: 4px;
  }
}

/* xlsx single-download card */
.bibtex-result__binary {
  padding: 24px 18px;
  text-align: center;
}
.bibtex-result__binary p {
  margin: 0 0 14px;
  font-size: .98rem;
  color: var(--color-text);
}

/* ---- Lead-gen card ---- */
.bibtex-lead {
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border-subtle);
  border-radius: var(--radius-md);
  padding: 20px 22px;
}
.bibtex-lead__text {
  margin: 0 0 14px;
  font-size: .96rem;
  line-height: 1.55;
  color: var(--color-text);
}
.bibtex-lead__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* ---- Per-page purple value pill (entry-type override etc.) ----
   Lives here, not in style.css, because the bibtex pages are the only
   consumers today. The purple --icon / --label variants are already
   defined in the shared style.css. */
.delivery-tier__value--purple { color: var(--color-purple-strong); }

/* ---- Tiers wrapper for stacked .delivery-tier cards in body ---- */
.bibtex-tiers {
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* "How it works"-style steps card mobile layout */
@media (max-width: 720px) {
  .bibtex-tier--steps .delivery-tier__row {
    grid-template-columns: 1fr;
  }
  .bibtex-tier--steps .delivery-tier__col--right {
    order: -1;
    align-items: flex-start;
  }
  .bibtex-tier--steps .delivery-tier__value { margin-bottom: 4px; }
}
