.filebird-gallery {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.filebird-gallery-toolbar {
    display: flex;
    justify-content: flex-end;
}

.filebird-view-switch {
    display: inline-flex;
    border: 1px solid rgba(0, 0, 0, 0.15);
    border-radius: 8px;
    overflow: hidden;
}

.filebird-view-radio {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.filebird-view-btn {
    display: flex;
    align-items: center;
    padding: 0.35em 0.6em;
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
    background: #fff;
    color: #888;
    user-select: none;
}

.filebird-view-radio-list + .filebird-view-btn {
    border-left: 1px solid rgba(0, 0, 0, 0.15);
}

.filebird-view-radio:checked + .filebird-view-btn {
    background: #efefef;
    color: inherit;
}

.filebird-gallery-folder-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    padding-bottom: 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 2px solid rgba(0, 0, 0, 0.08);
}

.filebird-gallery-folder-title {
    margin: 0;
    font-weight: 600;
}

.filebird-gallery-download-all {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.4em;
    padding: 0.4em 0.9em;
    border-radius: 999px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    background: #fff;
    color: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s ease, transform 0.15s ease;

    &::before {
        content: "\2193"; /* down arrow */
    }

    &:hover,
    &:focus-visible {
        background: #efefef;
        transform: translateY(-1px);
    }
}

.filebird-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.75rem;
}

.filebird-gallery-item {
    display: flex;
    flex-direction: column;
    border-radius: 8px;
    overflow: hidden;
    background: #f7f7f7;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
    text-decoration: none;
    color: inherit;
    transition: transform 0.15s ease, box-shadow 0.15s ease;

    &:hover,
    &:focus-visible {
        transform: translateY(-3px);
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
    }
}

.filebird-gallery-thumb {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    transition: transform 0.25s ease;

    .filebird-gallery-item:hover &,
    .filebird-gallery-item:focus-visible & {
        transform: scale(1.05);
    }
}

.filebird-gallery-file-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    aspect-ratio: 1 / 1;
    background: #e9e9e9;
    color: #777;
}

.filebird-gallery-file-svg {
    width: 40%;
    height: 40%;
}

.filebird-gallery-file-ext {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: #999;
}

.filebird-gallery-item-name {
    padding: 0.35rem 0.5rem;
    font-size: 0.72rem;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.filebird-gallery-subfolder {
    margin-top: 1.5rem;
    padding-left: 1.25rem;
    border-left: 3px solid rgba(0, 0, 0, 0.08);

    & .filebird-gallery-folder-title {
        font-size: 0.9em;
    }
}

/* List view: the list radio is checked, flip the grid into stacked rows. */
.filebird-gallery:has(.filebird-view-radio-list:checked) {
    & .filebird-gallery-grid {
        grid-template-columns: 1fr;
        gap: 0.25rem;
    }

    & .filebird-gallery-item {
        flex-direction: row;
        align-items: center;
        gap: 0.75rem;
        padding: 0.3rem 0.6rem;
        border-radius: 6px;
        box-shadow: none;
        border: 1px solid rgba(0, 0, 0, 0.06);

        &:hover,
        &:focus-visible {
            transform: none;
            box-shadow: none;
            background: #efefef;
        }
    }

    & .filebird-gallery-thumb,
    & .filebird-gallery-file-icon {
        width: 32px;
        height: 32px;
        flex-shrink: 0;
        border-radius: 4px;
    }

    & .filebird-gallery-file-svg {
        width: 55%;
        height: 55%;
    }

    & .filebird-gallery-file-ext {
        display: none; /* filename already shows the extension in list rows */
    }

    & .filebird-gallery-item-name {
        padding: 0;
        white-space: normal;
    }
}
