/* ClassiPress Core: photo gallery (two displays) + viewer. Every selector starts with .cpcg, so nothing here
   touches the theme. The viewer (.cpcg-lb) is appended to <body>. */

.cpcg { position: relative; margin: 0 0 1rem; direction: ltr; }
.cpcg *, .cpcg *::before, .cpcg *::after { box-sizing: border-box; }
.cpcg button { font: inherit; cursor: pointer; margin: 0; }
.cpcg img { display: block; max-width: none; }

/* ---- display 1: Divar-like ------------------------------------------------ */
.cpcg-stage { position: relative; border-radius: 12px; overflow: hidden; background: #111; outline-offset: 2px; }
.cpcg-slides { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }
.cpcg-slides::-webkit-scrollbar { display: none; }
.cpcg .cpcg-slide { flex: 0 0 100%; margin: 0; padding: 0; scroll-snap-align: center; aspect-ratio: 4 / 3; background: #111; display: flex; align-items: center; justify-content: center; cursor: zoom-in; }
.cpcg-ar-16-9 .cpcg-slide { aspect-ratio: 16 / 9; }
.cpcg-ar-1-1 .cpcg-slide { aspect-ratio: 1 / 1; }
.cpcg .cpcg-slide img { width: 100%; height: 100%; object-fit: contain; }
.cpcg-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 40px; height: 40px; border: 0; border-radius: 50%; background: rgba(255,255,255,.9); color: #222; font-size: 28px; line-height: 1; display: flex; align-items: center; justify-content: center; box-shadow: 0 1px 6px rgba(0,0,0,.3); opacity: .9; }
.cpcg-nav:hover { opacity: 1; background: #fff; }
.cpcg-prev { left: 10px; }
.cpcg-next { right: 10px; }
.cpcg-counter { position: absolute; left: 10px; bottom: 10px; padding: 3px 10px; border-radius: 14px; background: rgba(0,0,0,.65); color: #fff; font-size: 13px; line-height: 1.6; direction: ltr; }
.cpcg-expand { position: absolute; right: 10px; bottom: 10px; width: 34px; height: 34px; border: 0; border-radius: 8px; background: rgba(0,0,0,.65); color: #fff; font-size: 18px; line-height: 1; }
.cpcg-thumbs { display: flex; gap: 6px; margin-top: 8px; overflow-x: auto; scrollbar-width: thin; padding-bottom: 4px; }
.cpcg-thumb { flex: 0 0 auto; width: 84px; height: 64px; padding: 0; border: 2px solid transparent; border-radius: 8px; overflow: hidden; background: #e9ecef; opacity: .7; transition: opacity .15s, border-color .15s; }
.cpcg-thumb img { width: 100%; height: 100%; object-fit: cover; }
.cpcg-thumb:hover { opacity: 1; }
.cpcg-thumb.is-active { opacity: 1; border-color: #1d4ed8; }

/* arrows: the glyph depends on the reading direction (JS adds .cpcg-rtl on RTL pages) */
.cpcg-prev span::before { content: "\2039"; }
.cpcg-next span::before { content: "\203A"; }
.cpcg-rtl .cpcg-prev span::before { content: "\203A"; }
.cpcg-rtl .cpcg-next span::before { content: "\2039"; }
.cpcg-rtl .cpcg-prev { left: auto; right: 10px; }
.cpcg-rtl .cpcg-next { right: auto; left: 10px; }
.cpcg-rtl .cpcg-slides, .cpcg-rtl .cpcg-thumbs, .cpcg-rtl .cpcg-mosaic { direction: rtl; }
.cpcg-rtl .cpcg-counter { left: auto; right: 10px; }
.cpcg-rtl .cpcg-expand { right: auto; left: 10px; }
.cpcg-rtl .cpcg-all { left: auto; right: 12px; }

/* ---- display 2: mosaic --------------------------------------------------- */
.cpcg-mosaic { position: relative; display: grid; gap: 6px; border-radius: 12px; overflow: hidden; grid-template-columns: 2fr 1fr 1fr; grid-template-rows: 1fr 1fr; aspect-ratio: 16 / 9; background: #e9ecef; }
.cpcg-ar-4-3 .cpcg-mosaic { aspect-ratio: 4 / 3; }
.cpcg-ar-1-1 .cpcg-mosaic { aspect-ratio: 1 / 1; }
.cpcg-tile { position: relative; display: block; overflow: hidden; min-width: 0; min-height: 0; background: #dfe3e8; }
.cpcg-tile img { width: 100%; height: 100%; object-fit: cover; transition: transform .35s ease; }
.cpcg-tile:hover img { transform: scale(1.04); }
.cpcg-tile-0 { grid-column: 1; grid-row: 1 / 3; }
.cpcg-more { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.55); color: #fff; font-size: 1.4rem; font-weight: 700; }
.cpcg-all { position: absolute; left: 12px; bottom: 12px; z-index: 2; padding: 7px 14px; border: 0; border-radius: 20px; background: #fff; color: #222; font-size: 13px; box-shadow: 0 1px 6px rgba(0,0,0,.3); }
.cpcg-all:hover { background: #f1f3f5; }
.cpcg-tiles-1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.cpcg-tiles-2 { grid-template-columns: 2fr 1fr; grid-template-rows: 1fr; }
.cpcg-tiles-2 .cpcg-tile-0 { grid-row: 1; }
.cpcg-tiles-3 { grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; }
.cpcg-tiles-4 { grid-template-columns: 2fr 1fr 1fr; grid-template-rows: 1fr 1fr; }
.cpcg-tiles-4 .cpcg-tile-3 { grid-column: 2 / 4; }

@media (max-width: 640px) {
	.cpcg-nav { width: 34px; height: 34px; font-size: 24px; }
	.cpcg-thumb { width: 64px; height: 50px; }
	.cpcg-mosaic, .cpcg-ar-4-3 .cpcg-mosaic, .cpcg-ar-1-1 .cpcg-mosaic { aspect-ratio: auto; grid-template-columns: repeat(4, 1fr); grid-template-rows: auto auto; }
	.cpcg-mosaic .cpcg-tile-0 { grid-column: 1 / -1; grid-row: 1; aspect-ratio: 4 / 3; }
	.cpcg-mosaic .cpcg-tile:not(.cpcg-tile-0) { grid-column: auto !important; grid-row: 2; aspect-ratio: 1 / 1; }
	.cpcg-tiles-1, .cpcg-tiles-2, .cpcg-tiles-3 { grid-template-columns: repeat(3, 1fr); }
	.cpcg-tiles-1 { grid-template-rows: auto; }
}

/* ---- viewer (full screen) ----------------------------------------------- */
body.cpcg-lb-open { overflow: hidden; }
.cpcg-lb { position: fixed; inset: 0; z-index: 999999; display: flex; flex-direction: column; background: rgba(8,8,10,.96); color: #fff; direction: ltr; font: 14px/1.5 system-ui, sans-serif; }
.cpcg-lb[hidden] { display: none; }
.cpcg-lb button { font: inherit; color: inherit; cursor: pointer; margin: 0; }
.cpcg-lb-bar { flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 8px 12px; }
.cpcg-lb-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .85; direction: rtl; text-align: right; }
.cpcg-lb-count { flex: 0 0 auto; opacity: .85; font-variant-numeric: tabular-nums; }
.cpcg-lb-btn { width: 38px; height: 38px; border: 0; border-radius: 8px; background: rgba(255,255,255,.12); font-size: 18px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
.cpcg-lb-btn:hover, .cpcg-lb-btn.is-on { background: rgba(255,255,255,.28); }
.cpcg-lb-main { position: relative; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; touch-action: pan-y; }
.cpcg-lb-img { max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; user-select: none; -webkit-user-drag: none; transition: transform .2s ease, opacity .2s ease; cursor: zoom-in; }
.cpcg-lb.is-zoomed .cpcg-lb-img { transform: scale(2.2); cursor: zoom-out; }
.cpcg-lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 46px; height: 46px; border: 0; border-radius: 50%; background: rgba(255,255,255,.16); font-size: 30px; line-height: 1; display: flex; align-items: center; justify-content: center; z-index: 2; }
.cpcg-lb-nav:hover { background: rgba(255,255,255,.3); }
.cpcg-lb-prev { left: 12px; }
.cpcg-lb-next { right: 12px; }
.cpcg-lb-prev span::before { content: "\2039"; }
.cpcg-lb-next span::before { content: "\203A"; }
.cpcg-lb.cpcg-rtl .cpcg-lb-prev { left: auto; right: 12px; }
.cpcg-lb.cpcg-rtl .cpcg-lb-next { right: auto; left: 12px; }
.cpcg-lb.cpcg-rtl .cpcg-lb-prev span::before { content: "\203A"; }
.cpcg-lb.cpcg-rtl .cpcg-lb-next span::before { content: "\2039"; }
.cpcg-lb-caption { flex: 0 0 auto; padding: 4px 16px; text-align: center; min-height: 1.5em; opacity: .85; direction: rtl; }
.cpcg-lb-thumbs { flex: 0 0 auto; display: flex; gap: 6px; padding: 8px 12px 12px; overflow-x: auto; justify-content: safe center; }
.cpcg-lb-thumb { flex: 0 0 auto; width: 72px; height: 54px; padding: 0; border: 2px solid transparent; border-radius: 6px; overflow: hidden; background: #222; opacity: .55; }
.cpcg-lb-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cpcg-lb-thumb.is-active { opacity: 1; border-color: #fff; }
@media (max-width: 640px) {
	.cpcg-lb-nav { width: 38px; height: 38px; font-size: 24px; }
	.cpcg-lb-thumb { width: 56px; height: 42px; }
}

/* ---- dark mode (PeepSo Block Theme) -------------------------------------- */
body.ps-dark-mode .cpcg-mosaic, body.ps-dark-mode .cpcg-tile { background: #2a2d33; }
body.ps-dark-mode .cpcg-thumb { background: #2a2d33; }
body.ps-dark-mode .cpcg-thumb.is-active { border-color: #9db7ff; }
body.ps-dark-mode .cpcg-all { background: #2a2d33; color: #e6e8eb; }
body.ps-dark-mode .cpcg-all:hover { background: #343841; }
