/* ============================================================
   AutoGallery — Dark Mode Gallery
   Plugin by Juan David Ortiz · https://endupla.com

   All selectors are scoped to .ag-gallery, #ag-lightbox, or
   #ag-toast to prevent any conflict with themes or other plugins.
   CSS custom properties are declared locally (not on :root) so
   they never bleed into unrelated parts of the page.
   ============================================================ */

/* ── CSS variables scoped to plugin containers ───────────── */
.ag-gallery,
#ag-lightbox,
#ag-toast {
  --ag-bg:           #0f1015;
  --ag-surface:      #1a1c23;
  --ag-surface-2:    #22252f;
  --ag-border:       #2e3140;
  --ag-accent:       #4f8ef7;
  --ag-accent-hover: #6fa4ff;
  --ag-text:         #e4e6f0;
  --ag-text-muted:   #7b7f96;
  --ag-green:        #34d399;
  --ag-radius:       10px;
  --ag-radius-sm:    6px;
  --ag-transition:   0.22s cubic-bezier(0.4, 0, 0.2, 1);
  --ag-shadow:       0 4px 24px rgba(0, 0, 0, 0.6);
  --ag-gutter:       14px;
}

/* ── Box-sizing reset (isolated to plugin elements) ──────── */
.ag-gallery,
.ag-gallery *,
.ag-gallery *::before,
.ag-gallery *::after,
#ag-lightbox,
#ag-lightbox *,
#ag-lightbox *::before,
#ag-lightbox *::after,
#ag-toast,
#ag-toast * {
  box-sizing: border-box;
}

/* ── Gallery wrapper ─────────────────────────────────────── */
.ag-gallery {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ag-text);
  background: var(--ag-bg);
  padding: 28px 20px;
  border-radius: var(--ag-radius);
  width: 100%;
}

/* ── Search ──────────────────────────────────────────────── */
.ag-gallery .ag-search-wrap {
  margin-bottom: 20px;
}

.ag-gallery .ag-search {
  display: block;
  width: 100%;
  background: var(--ag-surface);
  border: 1px solid var(--ag-border);
  border-radius: 40px;
  padding: 10px 20px;
  color: var(--ag-text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--ag-transition), box-shadow var(--ag-transition);
  -webkit-appearance: none;
  appearance: none;
}

.ag-gallery .ag-search::placeholder {
  color: var(--ag-text-muted);
  opacity: 1;
}

.ag-gallery .ag-search:focus {
  border-color: var(--ag-accent);
  box-shadow: 0 0 0 3px rgba(79, 142, 247, 0.18);
}

/* ── Category filter bar ─────────────────────────────────── */
.ag-gallery .ag-filters {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -ms-flex-wrap: wrap;
      flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
  list-style: none;
  padding: 0;
  margin-top: 0;
}

.ag-gallery .ag-filter-btn {
  display: -webkit-inline-box;
  display: -ms-inline-flexbox;
  display: inline-flex;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  gap: 6px;
  background: var(--ag-surface);
  border: 1px solid var(--ag-border);
  color: var(--ag-text-muted);
  border-radius: 40px;
  padding: 7px 16px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--ag-transition), color var(--ag-transition), border-color var(--ag-transition);
  -webkit-user-select: none;
     -moz-user-select: none;
          user-select: none;
  white-space: nowrap;
}

.ag-gallery .ag-filter-btn:hover {
  background: var(--ag-surface-2);
  color: var(--ag-text);
  border-color: var(--ag-accent);
}

.ag-gallery .ag-filter-btn.ag-active {
  background: var(--ag-accent);
  border-color: var(--ag-accent);
  color: #fff;
  font-weight: 600;
}

.ag-gallery .ag-count {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
  line-height: 1.6;
}

.ag-gallery .ag-filter-btn.ag-active .ag-count {
  background: rgba(255, 255, 255, 0.25);
}

/* ── Grid ────────────────────────────────────────────────── */
.ag-gallery .ag-grid {
  display: -ms-grid;
  display: grid;
  gap: var(--ag-gutter);
}

/* Column definitions — fully scoped to avoid grid conflicts */
.ag-gallery .ag-grid.ag-cols-1 { -ms-grid-columns: 1fr; grid-template-columns: 1fr; }
.ag-gallery .ag-grid.ag-cols-2 { -ms-grid-columns: (1fr)[2]; grid-template-columns: repeat(2, 1fr); }
.ag-gallery .ag-grid.ag-cols-3 { -ms-grid-columns: (1fr)[3]; grid-template-columns: repeat(3, 1fr); }
.ag-gallery .ag-grid.ag-cols-4 { -ms-grid-columns: (1fr)[4]; grid-template-columns: repeat(4, 1fr); }
.ag-gallery .ag-grid.ag-cols-5 { -ms-grid-columns: (1fr)[5]; grid-template-columns: repeat(5, 1fr); }
.ag-gallery .ag-grid.ag-cols-6 { -ms-grid-columns: (1fr)[6]; grid-template-columns: repeat(6, 1fr); }

@media (max-width: 1100px) {
  .ag-gallery .ag-grid.ag-cols-5,
  .ag-gallery .ag-grid.ag-cols-6 { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 900px) {
  .ag-gallery .ag-grid.ag-cols-4,
  .ag-gallery .ag-grid.ag-cols-5,
  .ag-gallery .ag-grid.ag-cols-6 { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 640px) {
  .ag-gallery .ag-grid.ag-cols-3,
  .ag-gallery .ag-grid.ag-cols-4,
  .ag-gallery .ag-grid.ag-cols-5,
  .ag-gallery .ag-grid.ag-cols-6 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 400px) {
  .ag-gallery .ag-grid { grid-template-columns: 1fr; }
}

/* ── Gallery item ────────────────────────────────────────── */
.ag-gallery .ag-item {
  background: var(--ag-surface);
  border: 1px solid var(--ag-border);
  border-radius: var(--ag-radius);
  overflow: hidden;
  transition: -webkit-transform var(--ag-transition), transform var(--ag-transition),
              box-shadow var(--ag-transition);
  cursor: default;
}

.ag-gallery .ag-item:hover {
  -webkit-transform: translateY(-3px);
          transform: translateY(-3px);
  box-shadow: var(--ag-shadow);
  border-color: var(--ag-accent);
}

.ag-gallery .ag-item.ag-hidden {
  display: none;
}

/* ── Thumbnail ───────────────────────────────────────────── */
.ag-gallery .ag-thumb-wrap {
  position: relative;
  width: 100%;
  padding-top: 66.66%; /* 3:2 aspect ratio */
  overflow: hidden;
  background: var(--ag-surface-2);
}

.ag-gallery .ag-thumb {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  -o-object-fit: cover;
     object-fit: cover;
  display: block;
  transition: -webkit-transform 0.4s ease, transform 0.4s ease, -webkit-filter 0.3s, filter 0.3s;
}

.ag-gallery .ag-item:hover .ag-thumb {
  -webkit-transform: scale(1.05);
          transform: scale(1.05);
  -webkit-filter: brightness(0.55);
          filter: brightness(0.55);
}

/* ── Hover overlay ───────────────────────────────────────── */
.ag-gallery .ag-overlay {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  gap: 12px;
  opacity: 0;
  transition: opacity var(--ag-transition);
  background: rgba(15, 16, 21, 0.25);
}

.ag-gallery .ag-item:hover .ag-overlay {
  opacity: 1;
}

/* ── Shared button base ──────────────────────────────────── */
.ag-gallery .ag-btn,
#ag-lightbox .ag-btn {
  display: -webkit-inline-box;
  display: -ms-inline-flexbox;
  display: inline-flex;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  gap: 6px;
  border: none;
  cursor: pointer;
  border-radius: var(--ag-radius-sm);
  padding: 9px 14px;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  text-decoration: none;
  transition: background var(--ag-transition), color var(--ag-transition),
              -webkit-transform 0.15s, transform 0.15s;
  line-height: 1;
  -webkit-user-select: none;
     -moz-user-select: none;
          user-select: none;
}

.ag-gallery .ag-btn:hover,
#ag-lightbox .ag-btn:hover {
  -webkit-transform: scale(1.07);
          transform: scale(1.07);
}

.ag-gallery .ag-btn svg,
#ag-lightbox .ag-btn svg {
  width: 16px;
  height: 16px;
  -ms-flex-negative: 0;
      flex-shrink: 0;
  pointer-events: none;
}

.ag-gallery .ag-btn-view {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  -webkit-backdrop-filter: blur(6px);
          backdrop-filter: blur(6px);
}

.ag-gallery .ag-btn-view:hover {
  background: rgba(255, 255, 255, 0.28);
  color: #fff;
}

.ag-gallery .ag-btn-download,
#ag-lightbox .ag-btn-download {
  background: var(--ag-accent);
  color: #fff;
}

.ag-gallery .ag-btn-download:hover,
#ag-lightbox .ag-btn-download:hover {
  background: var(--ag-accent-hover);
  color: #fff;
}

/* ── Item info strip ─────────────────────────────────────── */
.ag-gallery .ag-info {
  padding: 10px 12px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
      -ms-flex-direction: column;
          flex-direction: column;
  gap: 3px;
}

.ag-gallery .ag-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--ag-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ag-gallery .ag-cat-label {
  font-size: 11px;
  color: var(--ag-accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

/* ── Empty / no-results states ───────────────────────────── */
.ag-gallery .ag-no-results {
  text-align: center;
  padding: 48px 20px;
  color: var(--ag-text-muted);
}

.ag-gallery.ag-empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--ag-text-muted);
  background: var(--ag-surface);
  border: 1px dashed var(--ag-border);
}

/* ══════════════════════════════════════════════════════════
   LIGHTBOX  (#ag-lightbox)
   All rules scoped via the unique page ID so they cannot
   conflict with other plugins' lightbox implementations.
   ══════════════════════════════════════════════════════════ */

#ag-lightbox {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 999990;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
}

#ag-lightbox .ag-lightbox-backdrop {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(5, 6, 10, 0.95);
  -webkit-backdrop-filter: blur(8px);
          backdrop-filter: blur(8px);
  cursor: zoom-out;
}

#ag-lightbox .ag-lightbox-inner {
  position: relative;
  z-index: 1;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: vertical;
  -webkit-box-direction: normal;
      -ms-flex-direction: column;
          flex-direction: column;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  max-width: 90vw;
  max-height: 90vh;
  width: 100%;
  -webkit-animation: ag-lb-in 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
          animation: ag-lb-in 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@-webkit-keyframes ag-lb-in {
  from { -webkit-transform: scale(0.88); transform: scale(0.88); opacity: 0; }
  to   { -webkit-transform: scale(1);    transform: scale(1);    opacity: 1; }
}

@keyframes ag-lb-in {
  from { -webkit-transform: scale(0.88); transform: scale(0.88); opacity: 0; }
  to   { -webkit-transform: scale(1);    transform: scale(1);    opacity: 1; }
}

#ag-lightbox .ag-lightbox-img-wrap {
  position: relative;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  max-width: 90vw;
  max-height: 80vh;
  overflow: hidden;
  border-radius: var(--ag-radius);
  background: var(--ag-surface);
  border: 1px solid var(--ag-border);
  box-shadow: 0 0 60px rgba(0, 0, 0, 0.9);
  min-width: 200px;
  min-height: 120px;
}

#ag-lightbox .ag-lightbox-img {
  display: block;
  max-width: 88vw;
  max-height: 78vh;
  -o-object-fit: contain;
     object-fit: contain;
  border-radius: var(--ag-radius);
  transition: opacity 0.3s;
}

#ag-lightbox .ag-lightbox-img.ag-loading {
  opacity: 0;
}

/* ── Spinner ─────────────────────────────────────────────── */
#ag-lightbox .ag-lightbox-spinner {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: none;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
}

#ag-lightbox .ag-lightbox-spinner.ag-visible {
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
}

#ag-lightbox .ag-lightbox-spinner span {
  display: block;
  width: 38px;
  height: 38px;
  border: 3px solid rgba(79, 142, 247, 0.2);
  border-top-color: var(--ag-accent);
  border-radius: 50%;
  -webkit-animation: ag-spin 0.8s linear infinite;
          animation: ag-spin 0.8s linear infinite;
}

@-webkit-keyframes ag-spin {
  to { -webkit-transform: rotate(360deg); transform: rotate(360deg); }
}

@keyframes ag-spin {
  to { -webkit-transform: rotate(360deg); transform: rotate(360deg); }
}

/* ── Footer (caption + download) ────────────────────────── */
#ag-lightbox .ag-lightbox-footer {
  margin-top: 14px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 88vw;
  -ms-flex-wrap: wrap;
      flex-wrap: wrap;
  -webkit-box-pack: justify;
      -ms-flex-pack: justify;
          justify-content: space-between;
}

#ag-lightbox .ag-lightbox-caption {
  color: var(--ag-text);
  font-size: 14px;
  font-weight: 500;
  -webkit-box-flex: 1;
      -ms-flex: 1;
          flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#ag-lightbox .ag-lightbox-dl {
  -ms-flex-negative: 0;
      flex-shrink: 0;
}

/* ── Navigation & close buttons ─────────────────────────── */
#ag-lightbox .ag-lightbox-close,
#ag-lightbox .ag-lightbox-prev,
#ag-lightbox .ag-lightbox-next {
  position: fixed;
  background: rgba(30, 32, 44, 0.88);
  border: 1px solid var(--ag-border);
  color: var(--ag-text);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  -webkit-box-pack: center;
      -ms-flex-pack: center;
          justify-content: center;
  cursor: pointer;
  transition: background var(--ag-transition), -webkit-transform 0.15s, transform 0.15s;
  -webkit-backdrop-filter: blur(6px);
          backdrop-filter: blur(6px);
  z-index: 2;
  padding: 0;
  font-family: inherit;
}

#ag-lightbox .ag-lightbox-close svg,
#ag-lightbox .ag-lightbox-prev svg,
#ag-lightbox .ag-lightbox-next svg {
  width: 20px;
  height: 20px;
  pointer-events: none;
  display: block;
}

#ag-lightbox .ag-lightbox-close {
  top: 18px;
  right: 18px;
}

#ag-lightbox .ag-lightbox-prev {
  top: 50%;
  left: 14px;
  -webkit-transform: translateY(-50%);
          transform: translateY(-50%);
}

#ag-lightbox .ag-lightbox-next {
  top: 50%;
  right: 14px;
  -webkit-transform: translateY(-50%);
          transform: translateY(-50%);
}

#ag-lightbox .ag-lightbox-close:hover {
  background: rgba(220, 60, 60, 0.75);
}

#ag-lightbox .ag-lightbox-prev:hover,
#ag-lightbox .ag-lightbox-next:hover {
  background: rgba(79, 142, 247, 0.55);
}

#ag-lightbox .ag-lightbox-prev:hover {
  -webkit-transform: translateY(-50%) scale(1.1);
          transform: translateY(-50%) scale(1.1);
}

#ag-lightbox .ag-lightbox-next:hover {
  -webkit-transform: translateY(-50%) scale(1.1);
          transform: translateY(-50%) scale(1.1);
}

/* ══════════════════════════════════════════════════════════
   TOAST  (#ag-toast)
   ══════════════════════════════════════════════════════════ */

#ag-toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  -webkit-transform: translateX(-50%) translateY(12px);
          transform: translateX(-50%) translateY(12px);
  background: var(--ag-surface-2);
  border: 1px solid var(--ag-green);
  border-radius: 40px;
  padding: 10px 22px;
  color: var(--ag-green);
  font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-weight: 600;
  display: -webkit-box;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: center;
      -ms-flex-align: center;
          align-items: center;
  gap: 8px;
  box-shadow: 0 6px 32px rgba(0, 0, 0, 0.6);
  z-index: 1000000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s, -webkit-transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  transition: opacity 0.35s, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
  max-width: 92vw;
  line-height: 1.4;
}

#ag-toast svg {
  width: 16px;
  height: 16px;
  -ms-flex-negative: 0;
      flex-shrink: 0;
  display: block;
}

#ag-toast.ag-toast-show {
  opacity: 1;
  -webkit-transform: translateX(-50%) translateY(0);
          transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

/* ── Focus styles (accessibility) ────────────────────────── */
.ag-gallery .ag-filter-btn:focus-visible,
.ag-gallery .ag-btn:focus-visible,
#ag-lightbox .ag-btn:focus-visible,
#ag-lightbox .ag-lightbox-close:focus-visible,
#ag-lightbox .ag-lightbox-prev:focus-visible,
#ag-lightbox .ag-lightbox-next:focus-visible {
  outline: 2px solid var(--ag-accent);
  outline-offset: 2px;
}

/* ── Scrollbar styling (webkit, scoped to gallery) ───────── */
.ag-gallery ::-webkit-scrollbar {
  width: 6px;
}

.ag-gallery ::-webkit-scrollbar-track {
  background: var(--ag-surface);
}

.ag-gallery ::-webkit-scrollbar-thumb {
  background: var(--ag-border);
  border-radius: 3px;
}
