/* ================================================
   COA Manager v3.1 — Frontend CSS
   ================================================ */

/* ---- Grid ---- */
.coa-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    padding: 10px 0;
    align-items: start;
    overflow: clip;
}
.coa-cols-1 { grid-template-columns: repeat(1, 1fr); }
.coa-cols-2 { grid-template-columns: repeat(2, 1fr); }
.coa-cols-3 { grid-template-columns: repeat(3, 1fr); }
.coa-cols-4 { grid-template-columns: repeat(4, 1fr); }

.coa-grid > * {
    min-width: 0;
}

/* ---- Base card ---- */
.coa-card {
    position: relative;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border: 1px solid var(--coa-card-border, #e8e8e8);
    border-radius: var(--coa-card-radius, 12px);
    overflow: hidden;
    transition: box-shadow 0.22s ease, transform 0.22s ease;
    text-decoration: none;
    color: inherit;
    isolation: isolate;
    min-width: 0;
}

.coa-card:hover {
    box-shadow: 0 10px 30px var(--coa-card-shadow, rgba(0, 0, 0, 0.10));
    transform: translateY(-3px);
}

/* ---- Card media area ---- */
.coa-card__media {
    display: block;
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    overflow: hidden;
    background: #f4f4f4;
    flex-shrink: 0;
}

/* ---- Media link (wraps media for single-image + PDF cards) ---- */
.coa-card__media-link {
    display: block;
    text-decoration: none;
    color: inherit;
    flex-shrink: 0;
}

/* ---- Single image ---- */
.coa-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    background: #f7f8fa;
}

/* ================================================
   IMAGE LIGHTBOX
   ================================================ */

body.coa-image-lightbox-open {
    overflow: hidden;
}

.coa-image-lightbox[hidden] {
    display: none;
}

.coa-image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 72px;
}

.coa-image-lightbox__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.86);
    cursor: zoom-out;
}

.coa-image-lightbox__figure {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    max-width: min(1100px, 92vw);
    max-height: 86vh;
    margin: 0;
}

.coa-image-lightbox__image {
    display: block;
    max-width: 100%;
    max-height: calc(86vh - 38px);
    object-fit: contain;
    background: #ffffff;
    border-radius: 4px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

.coa-image-lightbox__caption {
    max-width: 100%;
    margin-top: 12px;
    color: #ffffff;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
    text-align: center;
}

.coa-image-lightbox__button {
    position: absolute;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.28);
    border-radius: 999px;
    background: rgba(20, 20, 20, 0.78);
    color: #ffffff;
    cursor: pointer;
    box-shadow: 0 12px 34px rgba(0, 0, 0, 0.32);
    transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.coa-image-lightbox__button:hover,
.coa-image-lightbox__button:focus-visible {
    background: rgba(255, 255, 255, 0.96);
    border-color: rgba(255, 255, 255, 0.72);
    color: #111111;
    outline: none;
    transform: scale(1.04);
}

.coa-image-lightbox__icon {
    width: 24px;
    height: 24px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.4;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.coa-image-lightbox__close {
    top: 22px;
    right: 22px;
}

.coa-image-lightbox__nav {
    top: 50%;
    transform: translateY(-50%);
}

.coa-image-lightbox__nav:hover,
.coa-image-lightbox__nav:focus-visible {
    transform: translateY(-50%) scale(1.04);
}

.coa-image-lightbox__nav--prev {
    left: 22px;
}

.coa-image-lightbox__nav--next {
    right: 22px;
}

/* ================================================
   CAROUSEL
   ================================================ */

.coa-carousel {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at top left, rgba(255,255,255,0.16), transparent 36%),
        linear-gradient(180deg, rgba(15, 23, 42, 0.02), rgba(15, 23, 42, 0.14));
}

.coa-carousel__viewport {
    position: absolute;
    inset: 0;
    overflow: hidden;
}

.coa-carousel__track {
    display: flex;
    width: 100%;
    height: 100%;
    transition: transform 0.45s cubic-bezier(0.22, 1, 0.36, 1);
    will-change: transform;
}

.coa-carousel__slide {
    position: relative;
    flex: 0 0 100%;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.coa-carousel__slide::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.04) 0%, rgba(15, 23, 42, 0) 35%, rgba(15, 23, 42, 0.12) 100%);
    pointer-events: none;
}

.coa-carousel__img-link {
    display: block;
    position: relative;
    inset: 0;
    text-decoration: none;
    width: 100%;
    height: 100%;
}

/* ---- Prev / Next buttons ---- */
.coa-carousel__btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 20;
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #222;
    padding: 0;
    opacity: 0;
    transition: opacity 0.2s ease, background 0.2s ease, transform 0.2s ease;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(10px);
}

.coa-card--carousel:hover .coa-carousel__btn,
.coa-card--carousel:focus-within .coa-carousel__btn {
    opacity: 1;
}

.coa-carousel__btn--prev { left: 12px; }
.coa-carousel__btn--next { right: 12px; }

.coa-carousel__btn:hover {
    background: #ffffff;
    transform: translateY(-50%) scale(1.05);
}

.coa-carousel__status {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 20;
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0 10px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.68);
    color: #fff;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.22);
    backdrop-filter: blur(8px);
}

.coa-carousel__count {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* ---- Dot indicators ---- */
.coa-carousel__dots {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 20;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.44);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.18);
    backdrop-filter: blur(8px);
}

.coa-carousel__dot {
    width: 9px;
    height: 8px;
    border-radius: 999px;
    border: none;
    background: rgba(255, 255, 255, 0.55);
    cursor: pointer;
    padding: 0;
    transition: background 0.2s ease, transform 0.2s ease, width 0.2s ease;
}

.coa-carousel__dot.is-active {
    background: #ffffff;
    width: 22px;
    transform: none;
}

/* On mobile show buttons at all times (no hover on touch) */
@media (hover: none) {
    .coa-carousel__btn {
        opacity: 0.7;
    }
}

@media (max-width: 700px) {
    .coa-image-lightbox {
        padding: 58px 14px 74px;
    }

    .coa-image-lightbox__figure {
        max-width: 100%;
        max-height: 78vh;
    }

    .coa-image-lightbox__image {
        max-height: calc(78vh - 42px);
    }

    .coa-image-lightbox__button {
        width: 42px;
        height: 42px;
    }

    .coa-image-lightbox__close {
        top: 12px;
        right: 12px;
    }

    .coa-image-lightbox__nav {
        top: auto;
        bottom: 16px;
        transform: none;
    }

    .coa-image-lightbox__nav:hover,
    .coa-image-lightbox__nav:focus-visible {
        transform: scale(1.04);
    }

    .coa-image-lightbox__nav--prev {
        left: calc(50% - 56px);
    }

    .coa-image-lightbox__nav--next {
        right: calc(50% - 56px);
    }
}

/* ================================================
   PDF CARD
   ================================================ */

.coa-card__media--pdf {
    height: 600px;
    aspect-ratio: auto;
    overflow-y: auto;
    overflow-x: hidden;
    background: #ffffff;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.coa-pdf-object {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 600px;
    border: 0;
    background: #ffffff;
}

.coa-pdf-fallback {
    min-height: 600px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 24px;
    text-align: center;
    background: #f7f8fa;
    color: #475467;
}

.coa-pdf-fallback p {
    margin: 0;
}

.coa-pdf-fallback__link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 8px 16px;
    border-radius: var(--coa-btn-radius, 4px);
    background: var(--coa-btn-bg, #0071a1);
    color: var(--coa-btn-color, #ffffff) !important;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
}

.coa-pdf-fallback__link:hover {
    filter: brightness(0.94);
    text-decoration: none;
}

/* Transparent click-catcher above iframe — desktop only */
.coa-pdf-overlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    background: transparent;
    cursor: pointer;
}

/* PDF iframe — desktop only */
.coa-pdf-iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: none;
    pointer-events: none;
    display: block;
    background: #fff;
}

/* ---- Mobile PDF placeholder ---- */
/* Hidden on desktop; shown on mobile where iframes don't render PDFs */
.coa-pdf-mobile-placeholder {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 15;           /* above iframe(z:auto) and overlay(z:10) */
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
    background: linear-gradient(145deg, #f0f4f8 0%, #e8edf2 100%);
    pointer-events: none;  /* parent <a> handles the click */
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
}

.coa-pdf-mobile-placeholder::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.04), rgba(15, 23, 42, 0.22));
}

.coa-pdf-mobile-placeholder--image::before {
    background: linear-gradient(180deg, rgba(15, 23, 42, 0.04), rgba(15, 23, 42, 0.34));
}

.coa-pdf-mobile-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    max-width: 90%;
}

.coa-pdf-icon {
    width: 52px;
    height: 52px;
    color: #e53e3e;        /* red PDF colour */
    flex-shrink: 0;
}

.coa-pdf-mobile-name {
    font-size: 13px;
    font-weight: 700;
    color: #222;
    text-align: center;
    line-height: 1.3;
    max-width: 90%;
    /* clamp to 2 lines */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.coa-pdf-mobile-placeholder--image .coa-pdf-mobile-name {
    color: #ffffff;
    text-shadow: 0 2px 10px rgba(15, 23, 42, 0.55);
}

.coa-pdf-mobile-cta {
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    background: #e53e3e;
    padding: 4px 12px;
    border-radius: 20px;
    letter-spacing: 0.02em;
    margin-top: 2px;
    box-shadow: 0 10px 20px rgba(229, 62, 62, 0.22);
}

/* ================================================
   CARD FOOTER — centred, theme-proof
   ================================================ */

.coa-card__footer {
    padding: 12px 16px;
    border-top: 1px solid #f0f0f0;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.coa-card .coa-card__label {
    font-size: var(--coa-label-size, 14px);
    font-weight: 600;
    color: #111111 !important;
    margin: 0;
    line-height: 1.35;
    text-align: center;
}

.coa-card .coa-card__label-link {
    display: block;
    font-size: var(--coa-label-size, 14px);
    font-weight: 600;
    color: #111111 !important;
    margin: 0;
    line-height: 1.35;
    text-align: center;
    text-decoration: none;
    transition: color 0.15s ease;
}

.coa-card .coa-card__label-link:hover {
    color: var(--coa-btn-bg, #0071a1) !important;
    text-decoration: underline;
}

/* ---- Empty state ---- */
.coa-empty {
    padding: 20px 0;
    color: #888;
    font-style: italic;
}

/* ---- Product-specific shortcode ---- */
.coa-product-certificate {
    width: 100%;
}

.coa-product-certificate__results {
    width: 100%;
}

.coa-product-certificate__message {
    margin: 0;
}

.coa-product-certificate__message--loading {
    color: #555;
}

.coa-card__footer--stacked {
    flex-direction: column;
    gap: 8px;
}

.coa-card .coa-card__expiry {
    margin: 0;
    font-size: 12px;
    line-height: 1.35;
    color: #555;
    text-align: center;
}

.coa-card .coa-card__expiry span {
    font-weight: 700;
}

.coa-card .coa-card__button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 7px 14px;
    border-radius: var(--coa-btn-radius, 4px);
    background: var(--coa-btn-bg, #0071a1);
    color: var(--coa-btn-color, #ffffff) !important;
    font-size: 13px;
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
    transition: filter 0.15s ease, transform 0.15s ease;
}

.coa-card .coa-card__button:hover {
    filter: brightness(0.94);
    transform: translateY(-1px);
    text-decoration: none;
}

.coa-product-certificate--layout-list .coa-product-certificate__cards {
    grid-template-columns: 1fr;
}

.coa-product-certificate--layout-list .coa-card {
    display: grid;
    grid-template-columns: minmax(160px, 220px) minmax(0, 1fr);
    align-items: stretch;
}

.coa-product-certificate--layout-list .coa-card__media,
.coa-product-certificate--layout-list .coa-card__media-link {
    min-width: 0;
}

.coa-product-certificate--layout-list .coa-card__media {
    height: 100%;
    min-height: 220px;
    aspect-ratio: auto;
}

.coa-product-certificate--layout-list .coa-card__media--pdf {
    height: 600px;
    min-height: 600px;
}

.coa-product-certificate--layout-list .coa-card__footer {
    border-top: 0;
    border-left: 1px solid #f0f0f0;
    justify-content: center;
}

/* ================================================
   Responsive
   ================================================ */

@media ( max-width: 1024px ) {
    .coa-grid,
    .coa-cols-3,
    .coa-cols-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Mobile: hide iframe, show placeholder */
@media ( max-width: 768px ) {
    .coa-grid {
        gap: 16px;
    }

    .coa-card {
        transform: none !important;
    }

    .coa-carousel__btn {
        width: 36px;
        height: 36px;
        font-size: 22px;
        opacity: 0.88;
    }

    .coa-carousel__status {
        top: 10px;
        right: 10px;
    }

    .coa-carousel__dots {
        bottom: 10px;
        gap: 6px;
        padding: 7px 10px;
    }

    .coa-pdf-iframe,
    .coa-pdf-overlay {
        display: none;
    }

    .coa-pdf-mobile-placeholder {
        display: flex;
    }

    .coa-card__media.coa-card__media--pdf {
        height: 560px;
    }

    .coa-pdf-object,
    .coa-pdf-fallback {
        min-height: 560px;
    }
}

@media ( max-width: 600px ) {
    .coa-grid,
    .coa-cols-2,
    .coa-cols-3,
    .coa-cols-4 {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .coa-card__media {
        aspect-ratio: auto;
        height: clamp(280px, 88vw, 420px);
    }

    .coa-card__footer {
        padding: 12px 14px;
    }

    .coa-product-certificate--layout-list .coa-card {
        display: flex;
    }

    .coa-product-certificate--layout-list .coa-card__media {
        height: clamp(280px, 88vw, 420px);
    }

    .coa-product-certificate--layout-list .coa-card__media.coa-card__media--pdf,
    .coa-card__media.coa-card__media--pdf {
        height: 520px;
    }

    .coa-pdf-object,
    .coa-pdf-fallback {
        min-height: 520px;
    }

    .coa-product-certificate--layout-list .coa-card__footer {
        border-top: 1px solid #f0f0f0;
        border-left: 0;
    }

    .coa-carousel__btn--prev {
        left: 10px;
    }

    .coa-carousel__btn--next {
        right: 10px;
    }
}

/* ================================================
   Certificates Tab — per-type badge + desktop columns
   Scope: only inside the WooCommerce product Certificates tab.
   Archive (.coa-search-wrap) and single-product shortcode output
   are NOT affected.
   ================================================ */

/* Desktop / tablet-landscape: force 3 per row inside the tab.
   Overrides the global @media (max-width: 1024px) → 2-col rule
   for widths above the mobile breakpoint (>=769px). */
@media ( min-width: 769px ) {
    .coa-tab-section .coa-grid,
    .coa-tab-section .coa-cols-1,
    .coa-tab-section .coa-cols-2,
    .coa-tab-section .coa-cols-3,
    .coa-tab-section .coa-cols-4 {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Small badge overlay on each card image (top-left) — replaces the old H3 section title. */
.coa-tab-section .coa-card {
    position: relative;
}

.coa-tab-section .coa-card::before {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 5;
    padding: 4px 10px;
    border-radius: 999px;
    background: var(--coa-btn-bg, #0071a1);
    color: var(--coa-btn-color, #ffffff);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    line-height: 1.2;
    pointer-events: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
}

.coa-tab-section--purity .coa-card::before {
    content: "Purity Test";
}

.coa-tab-section--metal .coa-card::before {
    content: "Metal Test";
}

/* Legacy (untyped) tab section — no badge. */
.coa-tab-section:not([class*="coa-tab-section--"]) .coa-card::before {
    content: none;
}

/* Small spacing between successive tab sections when they stack vertically. */
.coa-tab-section + .coa-tab-section {
    margin-top: 24px;
}

/* Desktop: when the tab has 2+ sections, arrange them side-by-side in a flex row.
   Each section becomes a slim column, so its internal 3-col grid collapses to 1.
   Mobile / below 769px: the row wrapper is a plain block, sections stack normally. */
@media ( min-width: 769px ) {
    .coa-tab-sections-row {
        display: flex;
        gap: 20px;
        align-items: flex-start;
    }

    .coa-tab-sections-row > .coa-tab-section {
        flex: 1 1 0;
        min-width: 0;
    }

    .coa-tab-sections-row > .coa-tab-section + .coa-tab-section {
        margin-top: 0;
    }

    .coa-tab-sections-row > .coa-tab-section .coa-grid {
        grid-template-columns: 1fr;
    }
}
