/*! BioCollex Refresh · module: coa-grid · COA archive page (html.bxrf-coa-on, body.page-id-194)
 * Phones (viewport below 640px): certificates two to a row with a compact card, a one-row
 * stats strip, a tighter legend and a search box on its own row. Tablet and desktop (640px
 * and up) keep the main stylesheet's layout untouched.
 * Sizes are CSS px; the theme zooms the page 1.1x, so a 390px iPhone lays out ~355px.
 * No vw units here: they resolve differently under zoom. Container units size the numbers.
 * coa-grid.js adds the "Lot history" toggle and the test badge in the purity box; the
 * .bxrf-cg-card / .bxrf-cg-on classes it sets switch those parts on, so the cards still
 * read correctly if the script never runs.
 */

/* Parts that only exist on phones */
.bxrf-cg-tog, .bxrf-cg-badge, .bxrf-cg-x, .bxrf-cg-tl-name { display: none; }
.bxrf-cg-nw { white-space: nowrap; }

@media (max-width: 639.98px) {

  /* ---------- Intro: the page's 16px gutter, less dead space ---------- */
  .bxrf-coa-on main > section:first-child > div.relative { min-height: 0; }
  .bxrf-coa-on main > section:first-child > div.relative > div { padding: 4px 16px 22px; }
  .bxrf-coa-on main > section:first-child h1 + p { margin-top: 10px; font-size: 14px !important; line-height: 1.5; text-wrap: pretty; }
  /* The third floating vial sat behind the numbers */
  .bxrf-coa-on main > section:first-child > div.pointer-events-none > div:nth-child(3) { display: none; }

  /* ---------- Live numbers ---------- */
  .bxrf-coa-on .bxrf-coa-stats { margin-top: 16px; }
  .bxrf-coa-on .bxrf-live { margin: 0 0 8px; padding: 4px 11px; font-size: 11.5px; gap: 7px; }

  /* ---------- Search on its own row; the count and the sort share the next one ---------- */
  .bxrf-coa-on main > section:nth-child(2) { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 10px; padding-top: 16px; }
  .bxrf-coa-on main > section:nth-child(2) > * { grid-column: 1 / -1; min-width: 0; }
  .bxrf-coa-on main > section:nth-child(2) > div:first-child { display: contents; }
  .bxrf-coa-on main > section:nth-child(2) > div:first-child > div:first-child { grid-column: 1 / -1; grid-row: 1; }
  .bxrf-coa-on main > section:nth-child(2) > div:first-child > div:last-child { grid-column: 2; grid-row: 2; margin-top: 10px; }
  .bxrf-coa-on main > section:nth-child(2) > p:not([data-bx-coa-empty]) { grid-column: 1; grid-row: 2; margin: 10px 0 0; text-align: left; line-height: 1.35; }
  .bxrf-coa-on #coa-search { height: 46px; font-size: 16px; } /* 16px: iPhone does not zoom in on tap */
  .bxrf-coa-on .bx-coa-sort { min-height: 40px; padding: 0 10px 0 12px; gap: 6px; font-size: 13px; }
  .bxrf-coa-on .bx-coa-sort > svg { display: none; }
  .bxrf-coa-on .bx-coa-sort select { font-size: 13px; }

  /* ---------- Filters and legend ---------- */
  .bxrf-coa-on .bxrf-coa-deck { gap: 10px; margin: 14px 0 18px; }
  .bxrf-coa-on .bxrf-coa-legend { justify-content: flex-start; gap: 5px; padding: 10px 12px 11px; border-radius: 16px; text-align: left; }
  .bxrf-coa-on .bxrf-coa-legend-h { flex-basis: 100%; margin-bottom: 1px; font-size: 10.5px; }
  .bxrf-coa-on .bxrf-coa-legend ul { display: contents; }
  .bxrf-coa-on .bxrf-coa-legend li { padding: 2px 8px; font-size: 11px; line-height: 18px; }

  /* ---------- Compact certificate card ---------- */
  .bxrf-coa-on [data-bx-coa-grid] { gap: 16px 10px; }
  .bxrf-coa-on [data-bx-coa-grid] > [data-name] { padding: 12px; border-radius: 18px !important; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-newtag { top: -8px; left: 10px; height: 18px; padding: 0 8px; font-size: 9px; letter-spacing: .05em; }

  /* Header: image, then the size chip and "Verified" beside it; the name underneath */
  .bxrf-coa-on [data-bx-coa-grid] > [data-name] > div:first-of-type {
    display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto auto auto;
    column-gap: 8px; row-gap: 0; align-items: center; container-type: inline-size;
  }
  /* Image and chips scale with the card, so "5MG/5MG" fits whole from 340px up */
  .bxrf-coa-on [data-bx-coa-grid] > [data-name] > div:first-of-type > a {
    grid-column: 1; grid-row: 1 / 3; width: 48px; height: 48px; width: clamp(44px, 40cqw, 56px); height: clamp(44px, 40cqw, 56px); border-radius: 13px;
  }
  .bxrf-coa-on [data-bx-coa-grid] > [data-name] > div:first-of-type > div,
  .bxrf-coa-on [data-bx-coa-grid] > [data-name] > div:first-of-type > div > div:first-child { display: contents; }
  .bxrf-coa-on [data-bx-coa-grid] > [data-name] > div:first-of-type > div > p { display: none; }
  /* size chip */
  .bxrf-coa-on [data-bx-coa-grid] > [data-name] > div:first-of-type > div > div:last-child { grid-column: 2; grid-row: 1; align-self: end; margin: 0 0 4px; gap: 4px; min-width: 0; }
  .bxrf-coa-on [data-bx-coa-grid] > [data-name] > div:first-of-type > div > div:last-child > span {
    max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; line-height: 18px; text-transform: uppercase;
    padding: 2px 7px; font-size: 10.5px; padding: 2px clamp(5px, 5cqw, 8px); font-size: clamp(9.5px, 8.6cqw, 11px);
  }
  /* "Verified": a quiet line under the chip */
  .bxrf-coa-on [data-bx-coa-grid] > [data-name] > div:first-of-type > div > div:first-child > span {
    grid-column: 2; grid-row: 2; align-self: start; justify-self: start; gap: 3px; padding: 0; height: auto;
    background: none; box-shadow: none; line-height: 16px; white-space: nowrap; font-size: 10.5px; font-size: clamp(9.5px, 8.6cqw, 11px);
  }
  .bxrf-coa-on [data-bx-coa-grid] > [data-name] > div:first-of-type > div > div:first-child > span svg { width: 12px; height: 12px; }
  .bxrf-coa-on [data-bx-coa-grid] > [data-name] h3 {
    grid-column: 1 / -1; grid-row: 3; margin-top: 9px;
    font-size: 15px; line-height: 1.2; letter-spacing: -.015em; overflow-wrap: anywhere; text-wrap: balance;
  }

  /* Purity: the strength box goes (the size chip already says it) */
  .bxrf-coa-on [data-bx-coa-grid] > [data-name] > div:nth-of-type(2) { margin-top: 9px; gap: 0; }
  .bxrf-coa-on [data-bx-coa-grid] > [data-name] > div:nth-of-type(2) > div:not(.bxrf-pbox) { display: none; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-pbox { min-width: 0; padding: 10px 40px 10px 11px !important; border-radius: 14px; container-type: inline-size; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-pbox > p:first-child {
    font-size: 17px; font-size: clamp(14px, 21cqw, 22px);
    font-weight: 700; letter-spacing: -.03em; white-space: nowrap;
  }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-pbox > p + p { margin-top: 5px; font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-ring { right: 7px; width: 28px; height: 28px; }

  /* With the test badge inside (coa-grid.js): number across the box, badge and ring underneath */
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-card .bxrf-pbox { padding: 11px 11px 9px !important; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-card .bxrf-pbox > p:first-child { font-size: 20px; font-size: clamp(15px, 21cqw, 26px); }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-card .bxrf-ring { top: auto; bottom: 9px; translate: none; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-card .bxrf-cg-badge {
    display: flex; width: max-content; max-width: calc(100% - 34px); margin: 9px 0 0; height: 28px; padding: 0;
    align-items: center; background: none; box-shadow: none;
  }
  .bxrf-cg-badge > span {
    display: inline-flex; align-items: center; height: 20px; padding: 0 8px; border-radius: 999px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    font-size: 10px; font-weight: 800; letter-spacing: .03em; text-transform: uppercase; color: var(--bxrf-navy-2, #213b66); background: #dfe8f8;
  }
  .bxrf-cg-badge.is-full > span { color: #fff; background: linear-gradient(135deg, #15803d, #22a35a); box-shadow: 0 6px 14px -8px rgba(21, 128, 61, .8); }
  .bxrf-cg-badge.is-legacy > span { color: #64748b; background: #eef2f7; }

  /* Lab panel block: the chips give way to the badge; the lot history folds behind a toggle */
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cc { margin-top: 8px; padding: 9px 10px; border-radius: 14px; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cc-head { justify-content: flex-start; margin: 0; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cc-label,
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cc-tests { display: none; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cc-count { height: 20px; padding: 0 8px; font-size: 10px; letter-spacing: .03em; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-card .bxrf-cc-head { display: none; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-on { padding: 0; overflow: hidden; }

  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-tog {
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 5px; row-gap: 2px;
    width: 100%; min-height: 46px; margin: 0; padding: 7px 9px 8px 10px; border: 0; border-radius: 0; cursor: pointer;
    text-align: left; font: inherit; color: var(--bxrf-ink, #0b1530); background: transparent;
    -webkit-tap-highlight-color: transparent; transition: background-color .2s;
  }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-tog:active { background: var(--bxrf-mist, #eef4fe); }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-tog:focus-visible { outline: 2px solid var(--bxrf-blue, #2a6ad0); outline-offset: -2px; border-radius: 14px; }
  .bxrf-cg-tog-h { min-width: 0; font-size: 9.5px; font-weight: 800; line-height: 14px; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; color: #64748b; }
  .bxrf-cg-tog-s { grid-column: 1 / -1; min-width: 0; font-size: 12px; font-weight: 700; line-height: 1.3; color: var(--bxrf-ink, #0b1530); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bxrf-cg-tog-s i { font-style: normal; font-weight: 600; color: var(--bxrf-muted, #5b6a7f); }
  .bxrf-cg-tog > svg { grid-column: 2; grid-row: 1; color: var(--bxrf-navy-2, #213b66); transition: transform .35s var(--bxrf-ease, ease); }

  /* Lot history: opens as a layer over the card itself, so the card (and its row) keeps its size.
     The heading, name and close button stay put; a long list of lots scrolls under them.
     Without coa-grid.js the timeline simply stays in place, stacked for the narrow card. */
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-on .bxrf-tl { display: none; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-open .bxrf-cg-on .bxrf-tl {
    display: flex; flex-direction: column; position: absolute; inset: 0; z-index: 1; margin: 0; padding: 11px 12px 4px; border: 0; border-radius: 17px;
    background: #fff; box-shadow: inset 0 0 0 1px var(--bxrf-sky, #b1cef7); overflow: hidden;
    animation: bxrf-cg-in .3s var(--bxrf-ease, ease) both;
  }
  /* The scrolling list also clips sideways, so it reaches 6px into the layer's padding: room for the
     current lot's pulsing ring. */
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-open .bxrf-cg-on .bxrf-tl ol { flex: 1 1 auto; min-height: 0; margin: 0 -6px; padding: 0 6px 6px; overflow-y: auto; overscroll-behavior: contain; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-on .bxrf-tl-h { flex: none; margin: 0; padding-right: 34px; min-height: 22px; font-size: 10px; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-x {
    position: absolute; top: 4px; right: 4px; display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border: 0; border-radius: 50%;
    background: transparent; color: var(--bxrf-navy-2, #213b66); cursor: pointer; -webkit-tap-highlight-color: transparent;
  }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-x::before { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: var(--bxrf-mist, #eef4fe); z-index: -1; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-x { isolation: isolate; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-x:focus-visible { outline: 2px solid var(--bxrf-blue, #2a6ad0); outline-offset: -4px; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-cg-tl-name { display: block; flex: none; margin: 3px 0 6px; padding-right: 26px; font-size: 14px; font-weight: 800; line-height: 1.2; letter-spacing: -.01em; color: var(--bxrf-ink, #0b1530); overflow-wrap: anywhere; }

  /* Timeline rows stacked for a narrow card */
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-tl ol { border-top: 1px dashed #dbe3ef; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-tl ol::before { display: none; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-tl li {
    display: flex; flex-wrap: wrap; align-items: center; column-gap: 6px; row-gap: 3px; min-height: 0; padding: 8px 0 7px 16px;
  }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-tl li:not(:last-child)::after {
    content: ""; position: absolute; left: 4px; top: 22px; bottom: -10px; width: 2px; border-radius: 2px; background: #dbe3ef;
  }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-tl li > i { top: 11px; left: 0; width: 10px; height: 10px; margin: 0; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-tl li > div { flex: 1 1 100%; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-tl li b { font-size: 12.5px; line-height: 1.3; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-tl li span { margin-top: 1px; font-size: 11px; line-height: 1.35; white-space: normal; overflow-wrap: anywhere; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-tl li em { flex: 1 0 auto; font-size: 13px; }
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-tl li button { flex: none; height: 32px; padding: 0 13px; font-size: 12px; }

  /* View COA: full width, a comfortable tap target */
  .bxrf-coa-on [data-bx-coa-grid] > [data-name] > .mt-auto { padding-top: 10px; }
  .bxrf-coa-on [data-bx-coa-grid] > [data-name] > .mt-auto a { min-height: 44px; gap: 6px; padding: 0 10px; border-radius: 12px; font-size: 14px; white-space: nowrap; }
}

/* Two to a row from 340px; narrower screens keep one compact card per row */
@media (min-width: 340px) and (max-width: 639.98px) {
  .bxrf-coa-on [data-bx-coa-grid] { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* The four numbers as one segmented strip */
  .bxrf-coa-on .bxrf-coa-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 2px; container-type: inline-size; }
  .bxrf-coa-on .bxrf-coa-stat { padding: 10px 3px 9px; border-radius: 5px; }
  .bxrf-coa-on .bxrf-coa-stat:nth-child(2) { border-radius: 16px 5px 5px 16px; }
  .bxrf-coa-on .bxrf-coa-stat:last-child { border-radius: 5px 16px 16px 5px; }
  .bxrf-coa-on .bxrf-coa-stat b { font-size: 18px; font-size: clamp(15px, 5.6cqw, 21px); }
  .bxrf-coa-on .bxrf-coa-stat span { margin-top: 3px; font-size: 11px; line-height: 1.25; text-wrap: balance; }
}

/* Narrow phones (360-374px viewport is ~330px of layout) */
@media (max-width: 374.98px) {
  .bxrf-cg-tog-s { font-size: 11px; }
}
@media (min-width: 340px) and (max-width: 359.98px) {
  .bxrf-coa-on [data-bx-coa-grid] { column-gap: 8px; }
  .bxrf-coa-on [data-bx-coa-grid] > [data-name] { padding: 10px; }
  .bxrf-cg-lot { display: none; }
  .bxrf-cg-tog-s { white-space: normal; }
  .bxrf-coa-on .bxrf-coa-stat span { font-size: 10px; }
}

@keyframes bxrf-cg-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  .bxrf-coa-on [data-bx-coa-grid] .bxrf-tl { animation: none !important; }
  .bxrf-coa-on .bxrf-cg-tog, .bxrf-coa-on .bxrf-cg-tog > svg { transition: none !important; }
}
