/**
 * WP Accessible Gallery - Frontend Styles
 * WCAG 2.1 AA compliant
 */

/* ===== Gallery Grid ===== */
.wag-gallery {
    margin: 24px 0;
}

.wag-gallery-grid {
    display: grid;
    grid-template-columns: repeat(var(--wag-columns, 3), 1fr);
    gap: var(--wag-gap, 16px);
    list-style: none;
    margin: 0;
    padding: 0;
}

.wag-gallery-item {
    margin: 0;
    padding: 0;
    overflow: hidden;
    border-radius: var(--wag-radius, 8px);
    background: #f5f5f5;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.wag-gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.wag-gallery-link {
    display: block;
    text-decoration: none;
    color: inherit;
    position: relative;
    overflow: hidden;
}

.wag-gallery-link:focus-visible {
    outline: 3px solid #005fcc;
    outline-offset: 2px;
    border-radius: var(--wag-radius, 8px);
}

.wag-gallery-image {
    display: block;
    width: 100%;
    height: auto;
    aspect-ratio: 1;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.wag-gallery-link:hover .wag-gallery-image,
.wag-gallery-link:focus .wag-gallery-image {
    transform: scale(1.05);
}

.wag-gallery-caption {
    padding: 8px 12px;
    font-size: 0.9em;
    color: #333;
    background: #fff;
    border-top: 1px solid #eee;
    text-align: center;
}

/* ===== Lightbox ===== */
.wag-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 999999;
    background: rgba(0, 0, 0, 0.92);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.wag-lightbox.wag-lightbox-open {
    opacity: 1;
    visibility: visible;
}

.wag-lightbox-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.wag-lightbox-image-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 90vw;
    max-height: 80vh;
}

.wag-lightbox-image {
    max-width: 90vw;
    max-height: 80vh;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.wag-lightbox-image.wag-loaded {
    opacity: 1;
}

.wag-lightbox-caption {
    color: #fff;
    font-size: 1em;
    text-align: center;
    padding: 12px 16px;
    max-width: 600px;
    margin-top: 8px;
}

.wag-lightbox-counter {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85em;
    text-align: center;
    padding: 4px 0;
}

/* Lightbox buttons */
.wag-lightbox-btn {
    position: absolute;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    font-size: 1.3em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
    z-index: 10;
    line-height: 1;
    padding: 0;
}

.wag-lightbox-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.6);
}

.wag-lightbox-btn:focus-visible {
    outline: 3px solid #fff;
    outline-offset: 2px;
    background: rgba(255, 255, 255, 0.3);
}

.wag-lightbox-btn:active {
    transform: scale(0.95);
}

.wag-lightbox-close {
    top: 16px;
    right: 16px;
    position: fixed;
}

.wag-lightbox-prev {
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    position: fixed;
}

.wag-lightbox-next {
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    position: fixed;
}

.wag-lightbox-prev:active {
    transform: translateY(-50%) scale(0.95);
}

.wag-lightbox-next:active {
    transform: translateY(-50%) scale(0.95);
}

/* Lightbox loading spinner */
.wag-lightbox-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: wag-spin 0.8s linear infinite;
}

@keyframes wag-spin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* ===== Screen Reader Only ===== */
.wag-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ===== Skip Link ===== */
.wag-skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    background: #005fcc;
    color: #fff;
    padding: 8px 16px;
    z-index: 1000000;
    font-size: 0.9em;
    text-decoration: none;
    border-radius: 0 0 4px 0;
}

.wag-skip-link:focus {
    top: 0;
}

/* ===== Responsive ===== */
@media screen and (max-width: 1024px) {
    .wag-gallery-grid {
        --wag-columns: min(var(--wag-columns, 3), 3);
    }
}

@media screen and (max-width: 768px) {
    .wag-gallery-grid {
        --wag-columns: min(var(--wag-columns, 3), 2);
    }

    .wag-lightbox-btn {
        width: 40px;
        height: 40px;
        font-size: 1.1em;
    }

    .wag-lightbox-prev {
        left: 8px;
    }

    .wag-lightbox-next {
        right: 8px;
    }
}

@media screen and (max-width: 480px) {
    .wag-gallery-grid {
        --wag-columns: 1;
    }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    .wag-gallery-item,
    .wag-gallery-image,
    .wag-lightbox,
    .wag-lightbox-image,
    .wag-lightbox-btn {
        transition: none !important;
        animation: none !important;
    }

    .wag-gallery-item:hover {
        transform: none;
    }

    .wag-gallery-link:hover .wag-gallery-image,
    .wag-gallery-link:focus .wag-gallery-image {
        transform: none;
    }

    .wag-lightbox.wag-lightbox-open {
        opacity: 1;
    }

    .wag-lightbox-image.wag-loaded {
        opacity: 1;
    }
}

/* ===== High Contrast ===== */
@media (prefers-contrast: high) {
    .wag-gallery-item {
        border: 2px solid #000;
    }

    .wag-gallery-link:focus-visible {
        outline-width: 4px;
        outline-color: #000;
    }

    .wag-gallery-caption {
        color: #000;
        background: #fff;
        border-top: 2px solid #000;
    }

    .wag-lightbox {
        background: #000;
    }

    .wag-lightbox-btn {
        border-width: 3px;
        border-color: #fff;
        background: #000;
    }

    .wag-lightbox-btn:focus-visible {
        outline-width: 4px;
    }

    .wag-lightbox-caption {
        color: #fff;
    }
}

/* ===== Dark Mode ===== */
@media (prefers-color-scheme: dark) {
    .wag-gallery-item {
        background: #2a2a2a;
    }

    .wag-gallery-caption {
        color: #e0e0e0;
        background: #333;
        border-top-color: #444;
    }
}

/* ===== Print ===== */
@media print {
    .wag-lightbox {
        display: none !important;
    }

    .wag-gallery-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .wag-gallery-item {
        break-inside: avoid;
    }

    .wag-gallery-image {
        max-height: 200px;
    }
}
