/*
 * Gallery page: filter chips, photo grid and lightbox. Behaviour: assets/js/gallery.js.
 */

/* ---------- Filter chips ---------- */
.g-filters {
    display: flex;
    gap: .5rem;
    overflow-x: auto;
    padding: .25rem .25rem .75rem;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}
.g-filters[hidden] { display: none !important; }
.g-chip {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .55rem 1rem;
    border: 1px solid #e5e7eb;
    border-radius: 9999px;
    background: #fff;
    color: #374151;
    font-size: .875rem;
    font-weight: 600;
    line-height: 1.2;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .04);
    transition: background-color .2s ease, border-color .2s ease, color .2s ease, box-shadow .2s ease;
}
.g-chip:hover { border-color: #bfdbfe; background: #eff6ff; color: #1d4ed8; }
.g-chip[aria-pressed="true"] {
    border-color: #2563eb;
    background: #2563eb;
    color: #fff;
    box-shadow: 0 8px 18px -6px rgba(37, 99, 235, .55);
}
.g-chip[hidden] { display: none !important; }
.g-chip-count {
    min-width: 1.5rem;
    padding: .12rem .45rem;
    border-radius: 9999px;
    background: #f3f4f6;
    color: #4b5563;
    font-size: .75rem;
    font-weight: 700;
    text-align: center;
}
.g-chip[aria-pressed="true"] .g-chip-count { background: rgba(255, 255, 255, .22); color: #fff; }

/* ---------- Photo grid ("bento": tall tiles span two rows, the big tile two columns) ---------- */
.g-grid {
    display: grid;
    grid-template-columns: 1fr;
    grid-auto-rows: 12rem;
    grid-auto-flow: row dense;
    gap: 1rem;
    margin: 0;
    padding: 0;
    list-style: none;
}
@media (min-width: 640px) {
    .g-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 13rem; }
    .g-big { grid-column: span 2; }
}
@media (min-width: 1024px) {
    .g-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: 15rem; gap: 1.25rem; }
}
.g-tall, .g-big { grid-row: span 2; }
.g-item[hidden] { display: none !important; }
.g-item { animation: g-in .45s ease both; }
@keyframes g-in {
    from { opacity: 0; transform: translateY(12px) scale(.98); }
    to   { opacity: 1; transform: none; }
}

.g-card {
    position: relative;
    display: block;
    height: 100%;
    overflow: hidden;
    border-radius: 1rem;
    background: #e5e7eb;
    box-shadow: 0 12px 30px -14px rgba(15, 23, 42, .45);
    color: #fff;
    text-decoration: none;
    isolation: isolate;
}
.g-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .7s cubic-bezier(.2, .7, .2, 1);
}
.g-card:hover img,
.g-card:focus-visible img { transform: scale(1.06); }
.g-card::after {               /* dark fade at the bottom so captions stay readable */
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(15, 23, 42, .88) 0%, rgba(15, 23, 42, .35) 32%, rgba(15, 23, 42, 0) 58%);
    pointer-events: none;
}
.g-card:focus-visible { outline: 3px solid #1d4ed8; outline-offset: 3px; }

.g-meta {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1;
    padding: 1rem 1.1rem 1.05rem;
}
.g-cat {
    display: block;
    color: #bfdbfe;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
}
.g-title {
    display: block;
    margin-top: .2rem;
    font-family: 'Plus Jakarta Sans', 'Inter', sans-serif;
    font-size: 1.05rem;
    font-weight: 700;
    line-height: 1.3;
}

.g-badge {
    position: absolute;
    top: .75rem;
    left: .75rem;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .35rem .65rem;
    border-radius: 9999px;
    background: #16a34a;
    color: #fff;
    font-size: .68rem;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
    box-shadow: 0 6px 14px -4px rgba(22, 163, 74, .6);
}
.g-zoom {
    position: absolute;
    top: .75rem;
    right: .75rem;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 9999px;
    background: rgba(255, 255, 255, .92);
    color: #1d4ed8;
    opacity: 0;
    transform: scale(.85);
    transition: opacity .25s ease, transform .25s ease;
}
.g-card:hover .g-zoom,
.g-card:focus-visible .g-zoom { opacity: 1; transform: none; }
@media (hover: none) { .g-zoom { opacity: 1; transform: none; } }

/* ---------- Lightbox (<dialog id="lightbox">) ---------- */
html.g-lock { overflow: hidden; }
.lb {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    margin: 0;
    padding: 4.5rem 1rem 1.5rem;
    border: 0;
    background: transparent;
    color: #fff;
    overflow: hidden;
}
.lb[open] {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: lb-in .25s ease;
}
.lb::backdrop {
    background: rgba(2, 6, 23, .92);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}
@keyframes lb-in { from { opacity: 0; } to { opacity: 1; } }

.lb-figure {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: min(100%, 1100px);
    margin: 0;
    touch-action: pan-y pinch-zoom;   /* horizontal swipes go to the gallery (prev/next) */
}
.lb-img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: calc(100vh - 12rem);
    max-height: calc(100dvh - 12rem);
    border-radius: .75rem;
    background: #0f172a;
    box-shadow: 0 30px 60px rgba(0, 0, 0, .5);
    transition: opacity .25s ease;
}
.lb-figure.is-loading .lb-img { opacity: .35; }
.lb-figure.is-loading::after {
    content: '';
    position: absolute;
    top: calc(50% - 4rem);
    left: calc(50% - 1.25rem);
    width: 2.5rem;
    height: 2.5rem;
    border: 3px solid rgba(255, 255, 255, .25);
    border-top-color: #fff;
    border-radius: 9999px;
    animation: lb-spin .8s linear infinite;
}
@keyframes lb-spin { to { transform: rotate(360deg); } }

.lb-caption { max-width: 44rem; margin-top: 1rem; padding: 0 .5rem; text-align: center; }
.lb-title { font-family: 'Plus Jakarta Sans', 'Inter', sans-serif; font-size: 1.15rem; font-weight: 700; }
.lb-text { margin-top: .25rem; color: #cbd5e1; font-size: .9rem; line-height: 1.5; }
.lb-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    margin-top: .65rem;
    color: #94a3b8;
    font-size: .75rem;
}
.lb-label { padding: .25rem .6rem; border-radius: 9999px; font-weight: 700; }
.lb-label[data-kind="real"] { background: #16a34a; color: #fff; }
.lb-label[data-kind="stock"] { background: rgba(255, 255, 255, .12); color: #e2e8f0; }

.lb-btn {
    position: absolute;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    border: 1px solid rgba(255, 255, 255, .22);
    border-radius: 9999px;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background-color .2s ease;
}
.lb-btn:hover { background: rgba(255, 255, 255, .26); }
.lb .lb-btn:focus-visible { outline: 3px solid #93c5fd; outline-offset: 2px; }
.lb-btn[hidden] { display: none !important; }
.lb-close { top: 1rem; right: 1rem; }
.lb-prev  { top: 50%; left: 1rem; transform: translateY(-50%); }
.lb-next  { top: 50%; right: 1rem; transform: translateY(-50%); }
@media (max-width: 639px) {
    .lb { padding-bottom: 5.5rem; }
    .lb-prev, .lb-next { top: auto; bottom: 1.25rem; transform: none; }
    .lb-prev { left: calc(50% - 3.75rem); }
    .lb-next { right: calc(50% - 3.75rem); }
    .lb-img { max-height: calc(100vh - 16rem); max-height: calc(100dvh - 16rem); }
}

@media (prefers-reduced-motion: reduce) {
    .g-item, .lb[open] { animation: none; }
    .g-card img, .g-zoom, .lb-img { transition: none; }
}
