/* =================================================================
   Gallery module — compact grid + AJAX lightbox.
   Built on shared design tokens.
   ================================================================= */

.gallery-album-head {
    display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: .6rem; flex-wrap: wrap;
    padding: .5rem .7rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius, 5px);
}
.gallery-album-head-main { display: flex; align-items: center; gap: .55rem; min-width: 0; }
.gallery-album-owner-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.gallery-album-owner-avatar-initial {
    display: flex; align-items: center; justify-content: center;
    background: var(--indigo-soft, var(--paper)); color: var(--indigo); font-weight: 800; font-size: .82rem;
}
.gallery-album-head h1 { margin: 0; font-size: .92rem; line-height: 1.25; }
.gallery-album-head-main p { margin: 0; font-size: .76rem; line-height: 1.3; }
.gallery-album-head-main p:not(.muted) { margin-top: .1rem; }
.gallery-album-actions { display: flex; gap: .5rem; align-items: center; }

.gallery-album-menu { position: relative; flex-shrink: 0; }
.gallery-album-menu-btn {
    width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--border);
    background: var(--surface); color: var(--ink-soft); font-size: 1rem; cursor: pointer;
    transition: background .12s ease;
}
.gallery-album-menu-btn:hover, .gallery-album-menu.is-open .gallery-album-menu-btn { background: var(--paper); color: var(--ink); }
.gallery-album-menu-dropdown {
    display: none; position: absolute; top: calc(100% + 6px); right: 0; z-index: 30;
    min-width: 160px; padding: .35rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    box-shadow: 0 10px 28px -12px rgba(0,0,0,.35);
}
.gallery-album-menu.is-open .gallery-album-menu-dropdown { display: block; }
.gallery-album-menu-dropdown a, .gallery-album-menu-dropdown button, .gallery-album-menu-dropdown form { display: block; width: 100%; }
.gallery-album-menu-dropdown a, .gallery-album-menu-dropdown button {
    padding: .5rem .6rem; border-radius: 5px; border: none; background: none;
    font-family: inherit; font-size: .86rem; font-weight: 600; text-align: left;
    color: var(--ink); text-decoration: none; cursor: pointer;
}
.gallery-album-menu-dropdown a:hover, .gallery-album-menu-dropdown button:hover { background: var(--paper); }
.gallery-album-menu-danger { color: var(--danger) !important; }
.gallery-album-menu-danger:hover { background: rgba(214,69,90,.1) !important; }

.gallery-inline-form, .gallery-upload-form {
    display: none; flex-direction: column; gap: .3rem; margin-bottom: .6rem; padding: .65rem .75rem;
    position: relative; z-index: 1;
}
.gallery-inline-form.is-open { display: flex; }
.gallery-inline-form label, .gallery-upload-form label { font-size: .78rem; font-weight: 600; margin-top: .25rem; }
.gallery-inline-form input[type=text], .gallery-inline-form textarea,
.gallery-upload-form input[type=text], .gallery-upload-form textarea {
    padding: .45rem .6rem; border: 1px solid var(--border); border-radius: 5px;
    background: var(--paper); font-family: inherit; font-size: .85rem; resize: vertical;
}
.gallery-inline-form input[type=file], .gallery-upload-form input[type=file] { margin-top: .2rem; font-size: .82rem; }

/* The shared ajax-upload-error still uses order/flex (only the bar itself
   moved to absolute positioning) — reinforced here in case a stacking
   context quirk elsewhere on the page fights with it. */
.gallery-upload-form .ajax-upload-error, .gallery-inline-form .ajax-upload-error { order: -1; flex: 1 1 100%; width: 100%; position: relative; z-index: 2; }

/* ---------- Compact photo grid --------------------------------- */
.gallery-panel {
    background: var(--paper); border: 1px solid var(--border); border-radius: var(--radius, 5px);
    padding: .6rem; margin-bottom: 1.5rem;
}
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: .4rem;
}
.gallery-tile {
    position: relative; aspect-ratio: 1 / 1;
    border-radius: 8px; overflow: hidden; background: var(--paper);
    cursor: pointer;
}
.gallery-tile img {
    width: 100%; height: 100%; object-fit: cover; display: block;
    transition: transform .2s ease, filter .2s ease;
}
.gallery-tile:hover img { transform: scale(1.05); filter: brightness(.88); }

.gallery-tile-delete { position: absolute; top: 5px; right: 5px; }
.gallery-tile-delete button {
    width: 22px; height: 22px; border-radius: 50%; border: none;
    background: rgba(0,0,0,.55); color: #fff; font-size: .65rem;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* Slightly larger thumbnails on the album page — web (desktop) theme only,
   there's more room to breathe than on the compact touch layout. */
body.web-theme .gallery-album-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .55rem; }
body.web-theme .gallery-index-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .55rem; }

/* ---------- Album cards ---------------------------------------- */
.gallery-albums-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .6rem; }
.gallery-album-card {
    display: block; text-decoration: none; color: inherit;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 5px; overflow: hidden;
    transition: transform .1s ease, box-shadow .15s ease;
}
.gallery-album-card:hover { transform: translateY(-2px); box-shadow: 0 4px 14px -6px rgba(0,0,0,.15); }
.gallery-album-card img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
.gallery-album-card-placeholder { display: flex; align-items: center; justify-content: center; aspect-ratio: 4 / 3; font-size: 1.3rem; color: var(--ink-soft); background: var(--paper); }
.gallery-album-card-body { padding: .45rem .55rem; display: flex; flex-direction: column; gap: .1rem; }
.gallery-album-card-body strong { font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gallery-album-card-body span { font-size: .68rem; color: var(--ink-soft); }

/* ---------- Single photo detail view (gallery/photo.php) ------- */
.gallery-photo-view {
    display: flex; flex-direction: column; width: 100%;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    overflow: hidden; box-shadow: var(--shadow);
}
.gallery-photo-view img {
    width: 100%; max-height: 70vh; object-fit: contain; display: block; background: #000;
}
.gallery-photo-meta { padding: 1rem 1.2rem; }
.gallery-photo-meta-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; }
.gallery-photo-caption { font-size: 1rem; font-weight: 600; margin: .6rem 0 .4rem; }
.gallery-photo-byline { display: flex; align-items: center; gap: .5rem; margin: 0; flex-wrap: wrap; }
.gallery-photo-view .gallery-photo-author-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: none; }
.gallery-photo-view .gallery-photo-author-avatar-initial {
    display: flex; align-items: center; justify-content: center;
    background: var(--indigo-soft, var(--paper)); color: var(--indigo); font-weight: 800; font-size: .75rem;
}

/* Pagination uses the shared site-wide .pagination component — no gallery-specific overrides needed. */

/* ---------- Photo strip (profiles) ----------------------------- */
.photo-strip { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .2rem; }
.photo-strip a { flex-shrink: 0; width: 54px; height: 54px; border-radius: 7px; overflow: hidden; display: block; }
.photo-strip img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ---------- AJAX Lightbox ------------------------------------- */
.gallery-lb-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.88); z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    padding: 1rem;
    opacity: 0; transition: opacity .18s ease;
    pointer-events: none;
}
.gallery-lb-overlay.is-open { opacity: 1; pointer-events: auto; }

.gallery-lb-box {
    background: var(--surface); border-radius: 5px;
    max-width: 860px; width: 100%; max-height: 92vh;
    display: flex; flex-direction: column;
    overflow: hidden; position: relative;
    transform: scale(.96); transition: transform .18s ease;
    box-shadow: 0 24px 60px -8px rgba(0,0,0,.55);
}
.gallery-lb-overlay.is-open .gallery-lb-box { transform: scale(1); }

.gallery-lb-img-wrap { flex: 1; overflow: hidden; background: #000; min-height: 200px; position: relative; }
.gallery-lb-img-wrap img {
    width: 100%; height: 100%; object-fit: contain; display: block;
    max-height: 62vh;
}
.gallery-lb-spinner {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; color: rgba(255,255,255,.5);
    animation: lbSpin 1s linear infinite;
}
@keyframes lbSpin { to { transform: rotate(360deg); } }

.gallery-lb-close {
    position: absolute; top: .6rem; right: .75rem;
    width: 34px; height: 34px; border-radius: 50%; border: none;
    background: rgba(0,0,0,.55); color: #fff; font-size: 1.1rem;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    z-index: 5;
}

/* Prev / Next nav buttons */
.gallery-lb-nav {
    position: absolute; top: 50%; transform: translateY(-50%);
    width: 38px; height: 38px; border-radius: 50%; border: none;
    background: rgba(0,0,0,.5); color: #fff; font-size: 1.5rem; line-height: 1;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    z-index: 5; transition: background .15s ease;
}
.gallery-lb-nav:hover   { background: rgba(0,0,0,.75); }
.gallery-lb-nav:disabled { opacity: .25; cursor: default; }
.gallery-lb-prev { left:  .6rem; }
.gallery-lb-next { right: .6rem; }

.gallery-lb-footer {
    padding: .85rem 1.1rem; display: flex; flex-direction: column; gap: .55rem;
    border-top: 1px solid var(--border);
}
.gallery-lb-caption { font-size: .95rem; font-weight: 600; margin: 0; }
.gallery-lb-meta { font-size: .78rem; color: var(--ink-soft); }

.gallery-lb-actions { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }

.gallery-lb-react-btn {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: .45rem .9rem; border-radius: 5px; border: 1px solid var(--border);
    background: var(--paper); font-size: .85rem; font-weight: 700; cursor: pointer;
    transition: background .12s ease, border-color .12s ease;
}
.gallery-lb-react-btn:hover { background: var(--border); }
.gallery-lb-react-btn.is-active-like  { background: rgba(42,157,111,.12); border-color: var(--success); color: var(--success); }
.gallery-lb-react-btn.is-active-dislike { background: rgba(214,69,90,.1); border-color: var(--danger); color: var(--danger); }
.gallery-lb-react-btn .lb-count { font-size: .8rem; }

.gallery-lb-bookmark-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 38px; height: 38px; border-radius: 5px; border: 1px solid var(--border);
    background: var(--paper); color: var(--ink-soft); font-size: .9rem; cursor: pointer;
    transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.gallery-lb-bookmark-btn:hover { background: var(--border); }
.gallery-lb-bookmark-btn.is-active-bookmark { border-color: var(--indigo); color: var(--indigo); background: var(--indigo-soft, var(--paper)); }

.gallery-lb-download {
    margin-left: auto; display: inline-flex; align-items: center; gap: .35rem;
    padding: .45rem .9rem; border-radius: 5px; border: 1px solid var(--border);
    background: var(--paper); font-size: .82rem; font-weight: 600;
    text-decoration: none; color: var(--ink);
    transition: background .12s ease;
}
.gallery-lb-download:hover { background: var(--border); }

.gallery-lb-delete {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .45rem .9rem; border-radius: 5px;
    border: 1px solid rgba(214,69,90,.3); background: rgba(214,69,90,.06);
    color: var(--danger); font-size: .82rem; font-weight: 600; cursor: pointer;
}

.gallery-lb-login-note { font-size: .8rem; color: var(--ink-soft); }
.gallery-lb-login-note a { font-weight: 600; color: var(--indigo); }

/* ---------- Responsive ---------------------------------------- */
@media (max-width: 640px) {
    .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: .3rem; }
    .gallery-lb-box { border-radius: 5px; }
    .gallery-lb-footer { padding: .65rem .85rem; }
    .gallery-lb-download { margin-left: 0; }
    .gallery-photo-view { border-radius: 8px; }
    .gallery-photo-view img { max-height: 50vh; }
}

/* ---------- Multi-photo collage in the homepage feed --------------------
   Used only when an upload event has 2+ photos (a single photo uses the
   plain .feed-post-image treatment instead, uncropped). Layout adapts by
   count: 2 side-by-side, 3 one-large-two-small, 4 even grid, 5+ shows a
   "+N" overlay on the last tile.
   -------------------------------------------------------------------- */
.gl-feed-grid {
    display: grid; gap: 3px; border-radius: 10px; overflow: hidden;
    margin: .6rem 0 0; aspect-ratio: 16/10;
}
/* Note: a single photo never actually reaches .gl-feed-grid — it uses the
   separate .feed-post-image markup instead (see _feed_card.php), so there's
   no data-count="1" case to handle here. */
.gl-feed-grid[data-count="2"] { grid-template-columns: 1fr 1fr; }
.gl-feed-grid[data-count="3"] { grid-template-columns: 1.2fr 1fr; grid-template-rows: 1fr 1fr; }
.gl-feed-grid[data-count="3"] .gl-feed-grid-item:first-child { grid-row: 1 / 3; }
.gl-feed-grid[data-count="4"] { grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; }
.gl-feed-grid-item { position: relative; display: block; overflow: hidden; background: var(--paper); }
.gl-feed-grid-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gl-feed-grid-more {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    background: rgba(0,0,0,.5); color: #fff; font-size: 1.3rem; font-weight: 800;
}

/* ---------- Upload-event permalink page (gallery/upload.php) ------------ */
.gl-upload-page {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1.5rem 1.6rem; box-shadow: var(--shadow); margin-bottom: 1rem;
}
.gl-upload-byline { font-size: .92rem; margin-bottom: 1rem; }
.gl-upload-byline a { font-weight: 600; }
.gl-upload-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .5rem; margin-bottom: 1.2rem; }
.gl-upload-grid[data-count="1"] { grid-template-columns: 1fr; }
.gl-upload-grid-item { display: block; border-radius: 10px; overflow: hidden; aspect-ratio: 4/3; background: var(--paper); }
.gl-upload-grid[data-count="1"] .gl-upload-grid-item { aspect-ratio: 16/9; }
.gl-upload-grid-item img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s ease; }
.gl-upload-grid-item:hover img { transform: scale(1.04); }
