/* ─── Gallery Container ──────────────────────────────────────────────── */

.sg-gallery {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 80px);
    overflow: hidden;
}

/* ─── Header ─────────────────────────────────────────────────────────── */

.sg-gallery__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.sg-gallery__header-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
    min-width: 0;
}

.sg-gallery__header-right {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.sg-gallery__icon {
    color: var(--accent, #4ECDC4);
    display: flex;
}

.sg-gallery__name {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}

.sg-gallery__badge {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 4px;
    background: var(--accent, #4ECDC4);
    color: #0a0e17;
    letter-spacing: 0.04em;
}

.sg-gallery__meta {
    font-size: 0.8rem;
    color: var(--color-text-secondary, #8892A0);
}

.sg-gallery__status {
    font-size: 0.8rem;
    color: var(--accent, #4ECDC4);
    font-weight: 500;
}

/* ─── View Mode Buttons ──────────────────────────────────────────────── */

.sg-gallery__modes {
    display: flex;
    gap: 2px;
    background: rgba(255,255,255,0.05);
    border-radius: 6px;
    padding: 2px;
}

.sg-gallery__mode-btn {
    background: none;
    border: none;
    color: var(--color-text-secondary, #8892A0);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    transition: background 0.15s, color 0.15s;
}

.sg-gallery__mode-btn:hover {
    background: rgba(255,255,255,0.08);
    color: var(--color-text, #E0E0E0);
}

.sg-gallery__mode-btn--active {
    background: rgba(78, 205, 196, 0.15);
    color: var(--accent, #4ECDC4);
}

/* ─── Action Buttons ─────────────────────────────────────────────────── */

.sg-gallery__action-btn {
    background: none;
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--color-text-secondary, #8892A0);
    cursor: pointer;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    transition: border-color 0.15s, color 0.15s;
    white-space: nowrap;
}

.sg-gallery__action-btn:hover {
    border-color: var(--accent, #4ECDC4);
    color: var(--accent, #4ECDC4);
}

.sg-gallery__save-btn {
    background: var(--accent, #4ECDC4);
    color: #0a0e17;
    border: none;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: opacity 0.15s;
    white-space: nowrap;
}

.sg-gallery__save-btn:hover { opacity: 0.85; }

/* ═══════════════════════════════════════════════════════════════════════
   Grid — The Core Layout
   ═══════════════════════════════════════════════════════════════════════ */

.sg-gallery__grid {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    display: grid;
    gap: 0.75rem;
    align-content: start;
}

/* Grid mode: 4 columns, responsive */
.sg-gallery__grid--grid {
    grid-template-columns: repeat(4, 1fr);
}

/* Compact mode: 5+ columns */
.sg-gallery__grid--compact {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.5rem;
}

/* Large mode: 2 columns */
.sg-gallery__grid--large {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

/* ─── Responsive breakpoints ─────────────────────────────────────────── */

@media (max-width: 1200px) {
    .sg-gallery__grid--grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 800px) {
    .sg-gallery__grid--grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .sg-gallery__grid--large {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 500px) {
    .sg-gallery__grid--grid {
        grid-template-columns: 1fr;
    }
    .sg-gallery__grid--compact {
        grid-template-columns: repeat(2, 1fr);
    }
    .sg-gallery__header {
        flex-direction: column;
        align-items: flex-start;
    }
    .sg-gallery__header-right {
        width: 100%;
        justify-content: flex-start;
    }
}

/* ─── Thumbnail Cards ────────────────────────────────────────────────── */

.sg-thumb {
    cursor: pointer;
    border-radius: 8px;
    overflow: hidden;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
    transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
    min-width: 0;
    max-width: 100%;
}

.sg-thumb:hover {
    border-color: var(--accent, #4ECDC4);
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.sg-thumb__img {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    background-size: cover;
    background-position: center;
    background-color: rgba(255,255,255,0.02);
    background-repeat: no-repeat;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sg-thumb__badge {
    position: absolute;
    top: 6px;
    right: 6px;
    font-size: 0.55rem;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
    line-height: 1.4;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: white;
    z-index: 2;
    pointer-events: none;
}

.sg-thumb__label {
    padding: 6px 8px;
    font-size: 0.75rem;
    color: var(--color-text-secondary, #8892A0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Markdown text preview in thumbnail cards */
.sg-thumb__md-preview {
    position: absolute;
    inset: 0;
    padding: 10px;
    padding-right: 40px;
    font-size: 0.65rem;
    line-height: 1.4;
    color: rgba(255,255,255,0.4);
    overflow: hidden;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ═══════════════════════════════════════════════════════════════════════
   Lightbox
   ═══════════════════════════════════════════════════════════════════════ */

.sg-lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.92);
    display: none;
    flex-direction: column;
}

.sg-lightbox__header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    flex-shrink: 0;
}

.sg-lightbox__brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 700;
    color: var(--accent, #4ECDC4);
    font-size: 0.85rem;
}

.sg-lightbox__title {
    flex: 1;
    font-size: 0.85rem;
    color: var(--color-text, #E0E0E0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sg-lightbox__close {
    background: none;
    border: none;
    color: var(--color-text, #E0E0E0);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
}

.sg-lightbox__body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    padding: 1rem;
    gap: 0.5rem;
}

.sg-lightbox__nav {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    font-size: 2rem;
    cursor: pointer;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    flex-shrink: 0;
    transition: background 0.15s;
}

.sg-lightbox__nav:hover {
    background: rgba(255,255,255,0.2);
}

.sg-lightbox__content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    min-width: 0;
    overflow: auto;
}

.sg-lightbox__img {
    max-width: 90%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.sg-lightbox__doc {
    background: white;
    color: #1a1a1a;
    width: 70vw;
    padding: 2.5rem 3rem;
    border-radius: 8px;
    max-width: 900px;
    max-height: 80vh;
    overflow: auto;
    line-height: 1.6;
    box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

/* Markdown rendering in lightbox — parity with browse view */
.sg-lightbox__doc h1, .sg-lightbox__doc h2 { border-bottom: 1px solid #eee; padding-bottom: 0.5rem; }
.sg-lightbox__doc h3, .sg-lightbox__doc h4 { margin-top: 1.2em; }
.sg-lightbox__doc code { background: #f4f4f4; padding: 2px 6px; border-radius: 3px; font-size: 0.9em; color: #d63384; }
.sg-lightbox__doc pre { background: #f4f4f4; padding: 1rem; border-radius: 6px; overflow-x: auto; }
.sg-lightbox__doc pre code { background: none; padding: 0; color: #333; }
.sg-lightbox__doc blockquote { border-left: 3px solid #ddd; margin-left: 0; padding-left: 1rem; color: #555; }
.sg-lightbox__doc table { border-collapse: collapse; width: 100%; margin: 1em 0; }
.sg-lightbox__doc th, .sg-lightbox__doc td { border: 1px solid #ddd; padding: 8px; text-align: left; }
.sg-lightbox__doc th { background: #f4f4f4; font-weight: 600; }
.sg-lightbox__doc a { color: #0066cc; }
.sg-lightbox__doc img { max-width: 100%; }
.sg-lightbox__doc hr { border: none; border-top: 1px solid #e0e0e0; margin: 1.5em 0; }

.sg-lightbox__pdf {
    width: 90%;
    height: 80vh;
    border: none;
    border-radius: 8px;
}

.sg-lightbox__code {
    background: #1a1a2e;
    color: #e0e0e0;
    padding: 1.5rem;
    border-radius: 8px;
    max-width: 900px;
    max-height: 80vh;
    overflow: auto;
    font-size: 0.85rem;
    line-height: 1.5;
}

.sg-lightbox__footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid rgba(255,255,255,0.1);
    color: var(--color-text-secondary, #8892A0);
    font-size: 0.8rem;
    flex-shrink: 0;
}

.sg-lightbox__save {
    font-size: 0.75rem;
    padding: 4px 12px;
}

/* ─── Info Panel ─────────────────────────────────────────────────────── */

.sg-gallery__info {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 1rem;
    flex-shrink: 0;
    background: rgba(255,255,255,0.02);
}

.sg-gallery__info-content {
    max-width: 400px;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.sg-gallery__info-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    padding: 2px 0;
}

.sg-gallery__info-row span:first-child {
    color: var(--color-text-secondary, #8892A0);
}

.sg-gallery__info-row span:last-child {
    color: var(--color-text, #E0E0E0);
    font-weight: 500;
}

.sg-gallery__action-btn--active {
    border-color: var(--accent, #4ECDC4);
    color: var(--accent, #4ECDC4);
}

/* ─── Print ──────────────────────────────────────────────────────────── */

@media print {
    .sg-gallery { background: white !important; }
    .sg-gallery__header { display: none !important; }
    .sg-lightbox { display: none !important; }
    .sg-gallery__grid {
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        gap: 6px !important;
        overflow: visible !important;
        padding: 6px 0 !important;
    }
    .sg-thumb {
        break-inside: avoid;
        border: 1px solid #ccc !important;
        background: #f5f5f5 !important;
    }
    .sg-thumb__img {
        aspect-ratio: 4/3 !important;
        background-size: cover !important;
        print-color-adjust: exact !important;
        -webkit-print-color-adjust: exact !important;
    }
}
