/* Nav */
.nav-brand {
    text-decoration: none;
    color: inherit;
}

.nav-logout {
    margin: 0;
    display: flex;
    align-items: center;
}

.nav-logout button {
    margin: 0;
    padding: 0.3rem 0.8rem;
    font-size: 0.875rem;
}

/* Flash messages */
.flash {
    padding: 0.75rem 1rem;
    border-radius: var(--pico-border-radius, 4px);
    margin-bottom: 1rem;
    border: 1px solid transparent;
}

.flash--success,
.flash--info {
    background: #d4edda;
    border-color: #c3e6cb;
    color: #155724;
}

.flash--error {
    background: #f8d7da;
    border-color: #f5c6cb;
    color: #721c24;
}

/* Gallery header */
.gallery-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.gallery-header h2 {
    margin: 0;
}

.gallery-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Gallery grid */
.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.gallery-item {
    display: block;
    position: relative;
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: var(--pico-border-radius, 4px);
    background: #f0f0f0;
    transition: outline-color 0.1s;
}

.gallery-item__link {
    display: block;
    height: 100%;
    text-decoration: none;
}

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

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

/* Selection checkbox */
.gallery-checkbox {
    position: absolute;
    top: 0.4rem;
    left: 0.4rem;
    z-index: 2;
    width: 1.1rem;
    height: 1.1rem;
    margin: 0;
    cursor: pointer;
    accent-color: var(--pico-primary, #1095c1);
    opacity: 0;
    transition: opacity 0.15s;
}

.gallery-item:hover .gallery-checkbox,
.gallery-checkbox:checked {
    opacity: 1;
}

.gallery-item:has(.gallery-checkbox:checked) {
    outline: 3px solid var(--pico-primary, #1095c1);
    outline-offset: -3px;
}

/* Bulk action bar */
.bulk-action-bar {
    position: sticky;
    bottom: 1rem;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    margin-top: 0.5rem;
    background: var(--pico-card-background-color, #fff);
    border: 1px solid var(--pico-muted-border-color, #dee2e6);
    border-radius: var(--pico-border-radius, 4px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}

.bulk-action-bar input[type="text"] {
    flex: 1;
    min-width: 0;
    width: auto;
    margin: 0;
}

.bulk-action-bar button {
    flex-shrink: 0;
    width: auto;
    margin: 0;
    white-space: nowrap;
}

.bulk-action-bar select {
    flex-shrink: 0;
    width: auto;
    min-width: 8rem;
    max-width: 14rem;
    margin: 0;
}

.bulk-sep {
    display: block;
    width: 1px;
    align-self: stretch;
    background: var(--pico-muted-border-color, #dee2e6);
    margin: 0 0.25rem;
    flex-shrink: 0;
}

.bulk-count {
    white-space: nowrap;
    font-size: 0.875rem;
    font-weight: 600;
    min-width: 6rem;
}

.gallery-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.4rem 0.5rem;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 0.8rem;
    line-height: 1.3;
    opacity: 0;
    transition: opacity 0.2s ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-item:hover .gallery-caption {
    opacity: 1;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1.5rem;
}

.page-info {
    color: var(--pico-muted-color, #666);
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 4rem 1rem;
    color: var(--pico-muted-color, #666);
}

/* Upload card (noscript fallback) */
.upload-card {
    max-width: 560px;
}

/* Drag-and-drop zone */
.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;
}

.drop-zone {
    max-width: 560px;
    border: 2px dashed var(--pico-muted-border-color, #aaa);
    border-radius: var(--pico-border-radius, 4px);
    padding: 3rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    user-select: none;
    background: #f0f2f5;
    color: #212529;
}

@media (prefers-color-scheme: dark) {
    .drop-zone {
        background: #2a2f3d;
        color: #dee2e6;
    }
}

.drop-zone:hover,
.drop-zone:focus-visible {
    border-color: var(--pico-primary, #1095c1);
    outline: none;
}

.drop-zone--active {
    border-color: var(--pico-primary, #1095c1);
    background: rgba(16, 149, 193, 0.12);
}

.drop-zone__prompt {
    font-size: 1.2rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.drop-zone__sub {
    margin-bottom: 1rem;
}

.browse-link {
    cursor: pointer;
    color: var(--pico-primary, #1095c1);
    text-decoration: underline;
}

.drop-zone__hint {
    font-size: 0.85rem;
    color: var(--pico-muted-color);
    margin: 0;
}

/* File upload list */
.file-list {
    list-style: none;
    padding: 0;
    margin: 1rem 0;
    max-width: 560px;
}

.file-entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    border-radius: var(--pico-border-radius, 4px);
    margin-bottom: 0.4rem;
    font-size: 0.9rem;
    gap: 1rem;
    background: var(--pico-card-background-color, #f9f9f9);
    border: 1px solid var(--pico-muted-border-color, #eee);
}

.file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.file-status {
    white-space: nowrap;
    flex-shrink: 0;
    color: var(--pico-muted-color);
}

.file-entry--uploading .file-status {
    color: var(--pico-primary, #1095c1);
}

.file-entry--uploading .file-status::before {
    content: '';
    display: inline-block;
    width: 0.75em;
    height: 0.75em;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 0.3em;
}

.file-entry--done .file-status {
    color: #155724;
}

.file-entry--error .file-status {
    color: #721c24;
}

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

/* Image view */
.image-view {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 2rem;
    align-items: start;
}

@media (max-width: 768px) {
    .image-view {
        grid-template-columns: 1fr;
    }
}

.image-view__img {
    position: relative;
}

.image-view__img img {
    width: 100%;
    height: auto;
    border-radius: var(--pico-border-radius, 4px);
    display: block;
}

.image-nav__btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.45);
    color: #fff;
    font-size: 1.4rem;
    line-height: 1;
    padding: 0.6rem 0.5rem;
    border-radius: var(--pico-border-radius, 4px);
    text-decoration: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 2;
    user-select: none;
}

.image-view__img:hover .image-nav__btn {
    opacity: 1;
}

.image-nav__btn--prev { left: 0.5rem; }
.image-nav__btn--next { right: 0.5rem; }

.image-nav__back {
    display: inline-block;
    font-size: 0.8rem;
    color: var(--pico-muted-color);
    text-decoration: none;
    margin-bottom: 0.5rem;
}
.image-nav__back:hover { text-decoration: underline; }

.image-view__sidebar h2 {
    margin-top: 0;
    word-break: break-word;
}

/* Metadata list */
.image-meta {
    display: grid;
    grid-template-columns: auto 1fr;
    column-gap: 1rem;
    row-gap: 0.25rem;
    font-size: 0.9rem;
}

.image-meta dt {
    font-weight: 600;
    color: var(--pico-muted-color, #666);
    white-space: nowrap;
}

.image-meta dd {
    margin: 0;
    word-break: break-all;
}

/* Login page */
.login-wrap {
    max-width: 400px;
    margin: 4rem auto;
}

/* TOTP setup */
.totp-qr {
    margin: 1.5rem 0;
}

.totp-qr svg {
    display: block;
    width: 200px;
    height: 200px;
    border-radius: var(--pico-border-radius, 4px);
}

.totp-secret-wrap {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1rem 0;
}

.totp-secret {
    flex: 1;
    padding: 0.5rem 0.75rem;
    border-radius: var(--pico-border-radius, 4px);
    font-family: var(--pico-font-family-monospace, monospace);
    font-size: 1rem;
    letter-spacing: 0.08em;
    word-break: break-all;
    background: light-dark(#f0f2f5, #2a2f3d);
}

.totp-hint {
    font-size: 0.875rem;
    opacity: 0.75;
}

/* Tags */
.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
}

.tag {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    background: #e9ecef;
    color: #495057;
    border-radius: var(--pico-border-radius, 4px);
    font-size: 0.8rem;
    text-decoration: none;
    border: 1px solid #dee2e6;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.tag:hover {
    background: var(--pico-primary-background);
    color: var(--pico-primary-inverse);
    border-color: var(--pico-primary-background);
}

@media (prefers-color-scheme: dark) {
    .tag {
        background: #2a2f3d;
        color: #dee2e6;
        border-color: #3a4050;
    }
}

.tag-count {
    margin: 0;
    color: var(--pico-muted-color, #666);
    font-size: 0.9rem;
}

/* Machine tags — split-pill badges grouped by namespace */
.mtag-groups {
    display: grid;
    grid-template-columns: max-content 1fr;
    row-gap: 0.4rem;
    column-gap: 0.6rem;
    margin-bottom: 0.75rem;
    align-items: start;
}

.mtag-ns {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--pico-muted-color, #888);
    text-decoration: none;
    padding-top: 0.25rem;
}
.mtag-ns:hover { text-decoration: underline; }

.mtag-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.mtag {
    display: inline-flex;
    align-items: stretch;
    border-radius: var(--pico-border-radius, 4px);
    overflow: hidden;
    font-size: 0.75rem;
    line-height: 1.5;
    text-decoration: none;
    border: 1px solid var(--pico-muted-border-color, #dee2e6);
    transition: border-color 0.15s;
}
.mtag:hover { border-color: var(--pico-primary, #1095c1); }

.mtag__key {
    padding: 0.1rem 0.4rem;
    background: light-dark(#eef0f3, #2a2f3d);
    color: var(--pico-muted-color, #6c757d);
}

.mtag__val {
    padding: 0.1rem 0.4rem;
    background: light-dark(#fff, #191e2a);
    color: light-dark(#212529, #dee2e6);
}

.tags-mtag-toggle {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--pico-muted-color);
    margin-top: 0.25rem;
    width: fit-content;
    cursor: pointer;
}
.tags-mtag-toggle input[type="checkbox"] {
    width: auto;
    margin: 0;
}

/* Tag index page — namespace variant */
.tag-index-item--ns {
    border-style: dashed;
}

/* Tag index page */
.tag-index {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: baseline;
}

.tag-index-item {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.6rem;
    background: #e9ecef;
    color: #495057;
    border-radius: var(--pico-border-radius, 4px);
    font-size: 0.875rem;
    text-decoration: none;
    border: 1px solid #dee2e6;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.tag-index-item:hover {
    background: var(--pico-primary-background);
    color: var(--pico-primary-inverse);
    border-color: var(--pico-primary-background);
}

@media (prefers-color-scheme: dark) {
    .tag-index-item {
        background: #2a2f3d;
        color: #dee2e6;
        border-color: #3a4050;
    }
}

.tag-index-count {
    font-size: 0.75rem;
    opacity: 0.65;
}

/* Albums index — create form */
.album-create-form {
    margin-bottom: 2rem;
}

.album-create-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.album-create-row input {
    flex: 1;
    min-width: 0;
    width: auto;
    margin: 0;
}

.album-create-row button {
    flex-shrink: 0;
    width: auto;
    margin: 0;
}

/* Album grid */
.album-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.album-card {
    display: block;
    text-decoration: none;
    color: inherit;
    border-radius: var(--pico-border-radius, 4px);
    overflow: hidden;
    border: 1px solid var(--pico-muted-border-color, #dee2e6);
    transition: box-shadow 0.2s;
}

.album-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.album-card__cover {
    aspect-ratio: 1;
    overflow: hidden;
}

.album-card__cover img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.2s ease;
}

.album-card:hover .album-card__cover img {
    transform: scale(1.05);
}

.album-card__placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    color: var(--pico-muted-color, #666);
    font-size: 0.875rem;
}

@media (prefers-color-scheme: dark) {
    .album-card__placeholder {
        background: #2a2f3d;
    }
}

.album-card__info {
    padding: 0.5rem 0.75rem;
}

.album-card__title {
    display: block;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.album-card__count {
    display: block;
    font-size: 0.8rem;
    color: var(--pico-muted-color, #666);
}

/* Album description on show page */
.album-description {
    margin-top: -0.5rem;
    margin-bottom: 0;
    color: var(--pico-muted-color, #666);
}

/* Remove-from-album button (album show page) */
.gallery-item__remove {
    position: absolute;
    top: 0.4rem;
    right: 0.4rem;
    z-index: 2;
    margin: 0;
}

.gallery-item__remove-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    margin: 0;
    border-radius: 50%;
    border: none;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
}

.gallery-item:hover .gallery-item__remove-btn {
    opacity: 1;
}

/* Cover picker (album edit) */
.cover-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.cover-option {
    position: relative;
    cursor: pointer;
    display: block;
    width: 80px;
}

.cover-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.cover-option img,
.cover-option .album-card__placeholder {
    width: 80px;
    height: 80px;
    object-fit: cover;
    display: block;
    border-radius: var(--pico-border-radius, 4px);
    border: 2px solid transparent;
    transition: border-color 0.15s;
}

.cover-option:hover img,
.cover-option:hover .album-card__placeholder {
    border-color: var(--pico-muted-border-color, #dee2e6);
}

.cover-option:has(input:checked) img,
.cover-option:has(input:checked) .album-card__placeholder {
    border-color: var(--pico-primary, #1095c1);
}

/* Album sortable drag-and-drop (album edit) */
.sortable-item {
    cursor: grab;
    user-select: none;
}

.sortable-item:active {
    cursor: grabbing;
}

.sortable-item.drag-over {
    outline: 2px dashed var(--pico-primary, #1095c1);
    outline-offset: -2px;
}

.sortable-item.dragging {
    opacity: 0.4;
}

.drag-handle {
    position: absolute;
    top: 0.4rem;
    left: 0.4rem;
    z-index: 2;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    border-radius: 3px;
    padding: 0.1rem 0.3rem;
    font-size: 0.75rem;
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: none;
}

.gallery-item:hover .drag-handle {
    opacity: 1;
}

.album-reorder-hint {
    font-size: 0.875rem;
    color: var(--pico-muted-color, #666);
    margin-bottom: 0.75rem;
}

.reorder-status {
    margin-top: 0.5rem;
    font-size: 0.875rem;
    color: var(--pico-muted-color, #666);
}

/* Image view — albums list */
.image-albums {
    list-style: none;
    padding: 0;
    margin: 0 0 0.75rem;
}

.image-albums li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.2rem 0;
    font-size: 0.9rem;
}
