.view {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.search {
    flex: 1;
}

.actions {
    display: flex;
    gap: 8px;
}

.folder-section h2 {
    margin: 0 0 12px;
    font-size: 1.15rem;
    color: var(--title);
}

.folder-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
    gap: 16px;
}

.folder-card {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    color: var(--text);
    border-radius: 14px;
    box-shadow: var(--shadow);
    overflow: hidden;
    text-decoration: none;
}

.folder-card:hover .folder-cover img {
    transform: scale(1.03);
}

.folder-cover {
    aspect-ratio: 4 / 3;
    background: var(--secondary);
    display: grid;
    place-items: center;
    overflow: hidden;
}

.folder-cover:empty::after {
    content: "No photos yet";
    color: var(--muted);
    font-size: 0.9rem;
}

.folder-cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.folder-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 14px 14px;
}

.badges {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
}

.badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--secondary);
    color: var(--muted);
}

.badge.public {
    background: var(--ok-bg);
    color: var(--ok);
}

.badge.shared, .badge.link {
    background: color-mix(in srgb, var(--accent) 18%, transparent);
    color: var(--accent);
}

.storage {
    flex-direction: row;
    align-items: baseline;
    gap: 6px;
    min-width: 16em;
    padding: 10px 14px;
    border-radius: 8px;
    box-sizing: border-box;
}

.storage strong {
    font-size: inherit;
}

.tile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
}

.tile {
    position: relative;
    aspect-ratio: 1;
    padding: 0;
    border: none;
    border-radius: 10px;
    overflow: hidden;
    background: var(--secondary);
    cursor: pointer;
    box-shadow: var(--shadow);
}

.tile img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.tile-note, .tile-badge {
    position: absolute;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 700;
}

.tile-note {
    left: 0;
    right: 0;
    bottom: 0;
    padding: 6px 8px;
    background: rgba(0, 0, 0, 0.6);
}

.tile-badge {
    right: 6px;
    bottom: 6px;
    padding: 2px 7px;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.65);
}

.tile-name {
    position: absolute;
    inset: 10px 10px 34px;
    color: var(--text);
    font-size: 0.85rem;
    overflow-wrap: anywhere;
    overflow: hidden;
}

.tile-ext {
    position: absolute;
    left: 10px;
    bottom: 10px;
    padding: 2px 8px;
    border-radius: 6px;
    background: var(--accent);
    color: var(--on-accent);
    font-size: 0.8rem;
    font-weight: 700;
}

.upload-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.upload-list li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 4px 12px;
    font-size: 0.95rem;
}

.upload-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-list progress {
    grid-column: 1 / -1;
    width: 100%;
    height: 8px;
    accent-color: var(--accent);
}

.drop-hint {
    position: fixed;
    inset: 16px;
    z-index: 30;
    display: grid;
    place-items: center;
    border: 3px dashed var(--accent);
    border-radius: 16px;
    background: color-mix(in srgb, var(--accent) 14%, transparent);
    color: var(--title);
    font-size: 1.3rem;
    font-weight: 700;
    pointer-events: none;
}

.stage-dialog {
    width: min(100% - 32px, 620px);
}

.stage-list {
    list-style: none;
    margin: 0;
    padding: 4px;
    max-height: min(55vh, 520px);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stage-row {
    display: grid;
    grid-template-columns: 56px minmax(0, 1fr) auto;
    align-items: center;
    gap: 2px 12px;
}

.stage-preview {
    grid-row: span 2;
    width: 56px;
    height: 56px;
    border-radius: 8px;
    object-fit: cover;
    background: var(--secondary);
    display: grid;
    place-items: center;
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
}

.stage-row .button {
    grid-row: span 2;
}

.stage-row > :last-child {
    grid-column: 2;
    font-size: 0.85rem;
}

.stage-row.unusable .stage-preview {
    opacity: 0.5;
}

.name-field {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

.name-field input {
    flex: 1;
    min-width: 0;
}

.name-field .hint {
    min-width: 3em;
}

.dialog h3 {
    margin: 0 0 6px;
    font-size: 1rem;
}

.invite {
    display: block;
    padding: 14px 20px;
}

.invite summary {
    cursor: pointer;
    font-weight: 700;
    color: var(--title);
}

.invite[open] summary {
    margin-bottom: 14px;
}

.member-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.member-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-top: 1px solid var(--line);
}

/* The viewer covers the screen, with the photo or file in the middle and its details and buttons along the bottom. */
.viewer {
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100%;
    max-height: none;
    margin: 0;
    padding: 0;
    border: none;
    overflow: hidden;
    background: transparent;
    color: #e6edf7;
}

.viewer[open] {
    display: flex;
    flex-direction: column;
}

.viewer::backdrop {
    background: rgba(0, 0, 0, 0.85);
}

/* The extra space at the top keeps the close button clear of the photo or file. */
.viewer-stage {
    flex: 1;
    min-height: 0;
    display: grid;
    place-items: center;
    padding: 64px 16px 16px;
}

.viewer-stage img, .viewer-stage video {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* The thumbnail is stretched to where the full picture will appear, so nothing jumps when it arrives. */
.viewer-stage img.placeholder {
    width: 100%;
    height: 100%;
}

.viewer-document {
    width: min(100%, 1000px);
    height: 100%;
    border: none;
    border-radius: 8px;
    background: #fff;
}

.viewer-text, .viewer-sheet {
    box-sizing: border-box;
    max-width: 100%;
    max-height: 100%;
    margin: 0;
    overflow: auto;
    border-radius: 10px;
    background: #0f172a;
    color: #e6edf7;
    font-size: 0.85rem;
}

.viewer-text {
    padding: 16px;
    font-family: Consolas, "Courier New", monospace;
}

.viewer-text.wrap {
    max-width: min(100%, 80ch);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.viewer-table {
    width: max-content;
    margin: 0 auto;
    border-collapse: collapse;
}

.viewer-table th, .viewer-table td {
    padding: 6px 12px;
    border: 1px solid #334155;
    text-align: left;
    vertical-align: top;
}

/* Long values wrap within a column instead of making it endlessly wide, and keep their line breaks. */
.viewer-table div {
    max-width: 28em;
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

.viewer-table th {
    position: sticky;
    top: 0;
    background: #1e293b;
}

.viewer-table tbody tr:nth-child(even) {
    background: #131f35;
}

.sheet-note {
    margin: 0;
    padding: 12px;
    color: #cbd5e1;
}

.viewer-note {
    max-width: 360px;
    text-align: center;
    color: #cbd5e1;
}

.viewer-round {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    padding: 0 0 3px;
    border: none;
    border-radius: 50%;
    font: inherit;
    font-size: 1.8rem;
    line-height: 1;
    color: #e6edf7;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
}

.viewer-round:hover {
    background: rgba(255, 255, 255, 0.2);
}

.viewer-close {
    position: absolute;
    top: 12px;
    right: 12px;
}

.viewer-bar {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    grid-template-areas: "previous next info buttons";
    align-items: center;
    gap: 10px 12px;
    padding: 12px max(16px, (100% - 1200px) / 2);
    border-top: 1px solid #1e293b;
    background: #0f172a;
}

#viewer-previous {
    grid-area: previous;
}

#viewer-next {
    grid-area: next;
}

.viewer-info {
    grid-area: info;
    display: grid;
}

.viewer-info > * {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.viewer .hint {
    color: #94a3b8;
}

.viewer-buttons {
    grid-area: buttons;
    display: flex;
    gap: 8px;
}

.viewer-buttons .button.secondary {
    color: #e6edf7;
    background: rgba(255, 255, 255, 0.1);
}

.viewer-buttons .button.secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

.viewer-buttons .button.danger {
    color: #fca5a5;
    background: rgba(248, 113, 113, 0.15);
}

.viewer-buttons .button.danger:hover {
    background: rgba(248, 113, 113, 0.25);
}

/* On a phone the name sits between the arrows, with the buttons sharing the row underneath. */
@media (max-width: 640px) {
    .viewer-bar {
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-areas: "previous info next" "buttons buttons buttons";
    }

    .viewer-info {
        text-align: center;
    }

    .viewer-buttons {
        display: grid;
        grid-auto-flow: column;
        grid-auto-columns: 1fr;
    }

    .viewer-buttons .button {
        padding-block: 10px;
    }
}

@media (max-width: 480px) {
    .stage-dialog .dialog-buttons .button {
        flex: 1 1 40%;
    }
}

@media (max-width: 600px) {
    .toolbar > .spacer {
        display: none;
    }

    .actions, .actions > *, .storage {
        flex: 1 1 auto;
    }

    .actions > * {
        padding-inline: 10px;
    }

    .tile-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 4px;
    }

    .tile {
        border-radius: 6px;
    }
}
