/* =========================================
   Drive Gallery - Stylesheet
   ========================================= */

.dg-gallery {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    max-width: 1400px;
    margin: 0 auto;
    padding: 10px;
    box-sizing: border-box;
}

.dg-gallery *,
.dg-gallery *::before,
.dg-gallery *::after {
    box-sizing: border-box;
}

/* ---- Loading State ---- */
.dg-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: #555;
}

.dg-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid #e0e0e0;
    border-top-color: #4285f4;
    border-radius: 50%;
    animation: dg-spin 0.7s linear infinite;
}

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

.dg-loading p {
    margin: 12px 0 0;
    font-size: 14px;
    color: #777;
}

.dg-gallery.loaded .dg-loading {
    display: none;
}

/* ---- Grid ---- */
.dg-grid {
    display: grid;
    gap: 8px;
    width: 100%;
}

.dg-cols-1 .dg-grid { grid-template-columns: 1fr; }
.dg-cols-2 .dg-grid { grid-template-columns: repeat(2, 1fr); }
.dg-cols-3 .dg-grid { grid-template-columns: repeat(3, 1fr); }
.dg-cols-4 .dg-grid { grid-template-columns: repeat(4, 1fr); }
.dg-cols-5 .dg-grid { grid-template-columns: repeat(5, 1fr); }
.dg-cols-6 .dg-grid { grid-template-columns: repeat(6, 1fr); }

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

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

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

/* ---- Grid Item ---- */
.dg-item {
    position: relative;
    overflow: hidden;
    border-radius: 6px;
    cursor: pointer;
    aspect-ratio: 1 / 1;
    background: #f3f4f6;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.dg-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.dg-item:hover .dg-item-overlay {
    opacity: 1;
}

.dg-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.dg-item:hover img {
    transform: scale(1.05);
}

/* Video indicator */
.dg-item-video::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 48px;
    height: 48px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    pointer-events: none;
    z-index: 2;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 24px;
}

/* Overlay with title */
.dg-item-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 10px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    color: #fff;
    font-size: 12px;
    line-height: 1.3;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
    z-index: 3;
}

/* Error / empty state */
.dg-error {
    padding: 30px 20px;
    text-align: center;
    color: #c00;
    background: #fff5f5;
    border-radius: 8px;
    border: 1px solid #fecaca;
}

.dg-error p {
    margin: 0 0 8px;
}

.dg-error small {
    color: #666;
    font-size: 12px;
}

/* ---- Lightbox ---- */
.dg-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 999999;
    align-items: center;
    justify-content: center;
}

.dg-lightbox.active {
    display: flex;
}

.dg-lightbox-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    cursor: pointer;
}

.dg-lightbox-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    max-width: 90vw;
    max-height: 90vh;
}

.dg-lightbox-media {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 90vw;
    max-height: 82vh;
}

.dg-lightbox-media img {
    max-width: 90vw;
    max-height: 82vh;
    object-fit: contain;
    border-radius: 4px;
    user-select: none;
}

.dg-lightbox-media video {
    max-width: 90vw;
    max-height: 82vh;
    border-radius: 4px;
    background: #000;
}

.dg-lightbox-title {
    margin-top: 12px;
    color: #e0e0e0;
    font-size: 14px;
    text-align: center;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    max-width: 80vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Lightbox buttons */
.dg-lightbox-close,
.dg-lightbox-prev,
.dg-lightbox-next {
    position: absolute;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: #fff;
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s ease;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}

.dg-lightbox-close:hover,
.dg-lightbox-prev:hover,
.dg-lightbox-next:hover {
    background: rgba(255, 255, 255, 0.25);
}

.dg-lightbox-close {
    top: -48px;
    right: -8px;
    width: 40px;
    height: 40px;
    font-size: 28px;
    line-height: 1;
}

.dg-lightbox-prev,
.dg-lightbox-next {
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    font-size: 20px;
}

.dg-lightbox-prev {
    left: -56px;
}

.dg-lightbox-next {
    right: -56px;
}

@media (max-width: 768px) {
    .dg-lightbox-prev { left: 8px; }
    .dg-lightbox-next { right: 8px; }
    .dg-lightbox-close { top: -44px; right: 0; }
}

/* ---- Skeleton placeholders ---- */
.dg-skeleton {
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: dg-shimmer 1.5s ease-in-out infinite;
    border-radius: 6px;
    aspect-ratio: 1 / 1;
}

@keyframes dg-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
