/* Paper Mono, SIL Open Font License: /static/fonts/PaperMono-LICENSE.txt */
@font-face {
    font-family: "Paper Mono";
    font-style: normal;
    font-weight: 100 800;
    font-display: swap;
    src: url("/static/fonts/PaperMonoVariable.woff2") format("woff2");
}

/* Base document styles */
html, body {
    --app-gutter: 1rem;
    height: 100%;
    margin: 0;
    max-height: 100vh;
    overflow: hidden;
}

body {
    font-family: "Paper Mono", ui-monospace, monospace;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-weight: 400;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Prevent flash by hiding content until theme is applied */
html:not([data-theme]) {
    visibility: hidden;
}

html[data-theme] {
    visibility: visible;
}

html[data-theme='dark'] {
    color-scheme: dark;
}

html[data-theme='light'] {
    color-scheme: light;
}

/* Theme variables based on data attribute */
html[data-theme='light'] body,
body.light-mode {
    --bg-primary: #f0f2f5;
    --bg-surface: #fff;
    --bg-surface-hover: #f8fafc;
    --bg-overlay: rgb(0 0 0 / 60%);
    --bg-input: #f8fafc;
    --bg-input-focus: #fff;
    --text-primary: #111827;
    --text-secondary: #374151;
    --text-muted: #6b7280;
    --border-color: #cbd5e1;
    --border-color-light: #e2e8f0;
    --accent-indigo: #6366f1;
    --icon-filter: brightness(0) saturate(100%) invert(20%) sepia(15%) saturate(1200%) hue-rotate(174deg) brightness(
        90%
    ) contrast(95%);
}

html[data-theme='dark'] body,
body.dark-mode {
    --bg-primary: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-hover: #334155;
    --bg-overlay: rgb(0 0 0 / 40%);
    --bg-input: #334155;
    --bg-input-focus: #475569;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border-color: #475569;
    --border-color-light: #334155;
    --accent-indigo: #818cf8;
    --icon-filter: brightness(0) saturate(100%) invert(64%) sepia(11%) saturate(1015%) hue-rotate(174deg) brightness(
        95%
    ) contrast(87%);
}

/* Light Mode Variables */
body.light-mode {
    --bg-primary: #f0f2f5;
    --bg-surface: #fff;
    --bg-surface-hover: #f8fafc;
    --bg-overlay: rgb(0 0 0 / 60%);
    --bg-input: #f8fafc;
    --bg-input-focus: #fff;
    --text-primary: #111827;
    --text-secondary: #374151;
    --text-muted: #6b7280;
    --border-color: #cbd5e1;
    --border-color-light: #e2e8f0;
    --icon-filter: brightness(0) saturate(100%) invert(20%) sepia(15%) saturate(1200%) hue-rotate(174deg) brightness(
        90%
    ) contrast(95%);
}

/* Dark Mode Variables */
body.dark-mode {
    --bg-primary: #0f172a;
    --bg-surface: #1e293b;
    --bg-surface-hover: #334155;
    --bg-overlay: rgb(0 0 0 / 40%);
    --bg-input: #334155;
    --bg-input-focus: #475569;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border-color: #475569;
    --border-color-light: #334155;
    --accent-indigo: #818cf8;
    --icon-filter: brightness(0) saturate(100%) invert(64%) sepia(11%) saturate(1015%) hue-rotate(174deg) brightness(
        95%
    ) contrast(87%);
}

/* Reusable Component Classes */
.hover-surface {
    background-color: var(--bg-surface);
    border-radius: 0;
    transition: background-color 0.2s;
}

@media (hover: hover) {
    .hover-surface:hover,
    .card-action-btn:hover {
        background-color: var(--bg-surface-hover);
    }
}

.hover-card {
    background-color: var(--bg-surface);
}

.card-actions {
    position: absolute;
    top: 0;
    right: 0.625rem;
    display: inline-flex;
    align-items: stretch;
    gap: 2px;
    padding: 4px;
    z-index: 10;
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.gallery-card:hover .card-actions,
.gallery-card:focus-within .card-actions,
.card-actions:has(.card-action-popover:popover-open) {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.card-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    list-style: none;
    transition: background-color 0.2s;
}

summary::-webkit-details-marker {
    display: none;
}

/* .masonry-item img forces width:100%. */
.card-actions .card-action-btn img {
    width: 1rem;
    height: 1rem;
    flex: none;
}

.card-action-popover {
    position: fixed;
    inset: auto;
    margin: 6px 0;
    position-area: bottom span-left;
    position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline;
    width: 200px;
    padding: 8px 10px;
    border-radius: 6px;
    z-index: 20;
    font-size: 12px;
    color: var(--text-primary);
    cursor: default;
}

.card-action-popover-input {
    box-sizing: border-box;
    width: 100%;
    margin-top: 6px;
    padding: 4px 6px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 11px;
}

.card-action-popover-row {
    display: flex;
    justify-content: flex-end;
    margin-top: 6px;
}

.card-action-popover-save {
    padding: 2px 8px;
    border: none;
    border-radius: 4px;
    background-color: var(--accent-indigo);
    color: #fff;
    font-size: 10px;
}

.dropdown-container,
.card-action-popover {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
}

.focus-ring:focus-visible {
    outline: 2px solid var(--accent-indigo, #6366f1);
    outline-offset: 2px;
}

.toolbar-icon-button.focus-ring:focus-visible,
.search-submit.focus-ring:focus-visible {
    border-radius: 0.25rem;
    background-color: var(--bg-surface);
    transition: none;
}

.input-field,
.card-action-popover-input {
    background-color: var(--bg-input);
    color: var(--text-primary);
    transition: background-color 0.2s;
}

.input-field:focus,
.card-action-popover-input:focus {
    background-color: var(--bg-input-focus);
}

#search-input.input-field {
    border-color: var(--border-color-light);
    background-color: var(--bg-surface);
}

#search-input.input-field:focus {
    background-color: var(--bg-surface);
    outline: 2px solid var(--accent-indigo, #6366f1);
    outline-offset: 2px;
}

.text-muted {
    color: var(--text-muted);
}

.tag-badge {
    cursor: pointer;
    border-radius: 0;
    color: var(--text-secondary);
    text-decoration: underline;
    transition: background-color 0.2s, color 0.2s;
}

.tag-badge:hover {
    background-color: var(--bg-surface-hover);
    color: var(--text-primary);
}

#toasts-log {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 50;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: min(24rem, calc(100vw - 2rem));
    pointer-events: none;
}

#toasts-log .booru-toast {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-sizing: border-box;
    max-width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color-light);
    border-radius: 0.75rem;
    background-color: var(--bg-surface);
    color: var(--text-primary);
    pointer-events: auto;
}

#toasts-log .booru-toast-error {
    border-color: var(--border-color-light);
}

#toasts-log .booru-toast-error::before,
#toasts-log .booru-toast-success::before {
    flex: 0 0 auto;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 999px;
    content: '';
}

#toasts-log .booru-toast-error::before {
    background-color: #ef4444;
}

#toasts-log .booru-toast-success::before {
    background-color: #22c55e;
}

html[data-theme='dark'] #toasts-log .booru-toast-error::before,
body.dark-mode #toasts-log .booru-toast-error::before {
    background-color: #f87171;
}

html[data-theme='dark'] #toasts-log .booru-toast-success::before,
body.dark-mode #toasts-log .booru-toast-success::before {
    background-color: #4ade80;
}

#toasts-log .booru-toast-dismiss {
    margin-left: auto;
    appearance: none;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border-color-light);
    background-color: var(--bg-surface-hover);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.25;
}

#toasts-log .booru-toast-dismiss:hover {
    color: var(--text-primary);
}

/* Light mode specific improvements */
body.light-mode .font-medium {
    font-weight: 500;
}

body.light-mode .font-semibold {
    font-weight: 600;
}

.input-focus-underline {
    background-color: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
    padding-block: 0;
    margin: 0;
    line-height: 1.5;
    outline: none;
    transition: box-shadow 0.15s;
}

.input-focus-underline:focus {
    box-shadow: 0 2px 0 0 var(--accent-indigo);
}

/* Improve input field visibility */
body.light-mode input[type='search'] {
    border: 1px solid var(--border-color) !important;
}

body.light-mode input[type='search']:focus {
    border-color: #6366f1 !important;
    box-shadow: 0 0 0 3px rgb(99 102 241 / 10%) !important;
}

/* Better select styling */
body.light-mode select {
    border: 1px solid var(--border-color) !important;
}

/* Improve card borders */
body.light-mode .masonry-item > div {
    border: 1px solid var(--border-color-light);
}

/* Light mode placeholder improvements */
body.light-mode input::placeholder {
    color: var(--text-muted);
    opacity: 0.8;
}

/* Dark mode specific styles */
/* Improve form element appearance in dark mode */
body.dark-mode select option {
    background-color: var(--bg-surface);
    color: var(--text-primary);
}

html[data-theme='light'] .moon-icon {
    display: none;
}

html[data-theme='dark'] .sun-icon {
    display: none;
}

/* Ensure proper placeholder styling */
html[data-theme='dark'] input::placeholder {
    color: var(--text-muted);
    opacity: 1;
    font-weight: 400;
}

#filter-bar {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    min-height: 2.25rem;
    padding: 0.125rem 0 1rem;
}

.filter-chip {
    display: inline-flex;
    align-items: center;
    padding: 0;
    margin: 0.25rem 0.5rem;
}

.filter-chip[data-filter-key='tags'] > a::before {
    content: '#';
}

.gallery-view-input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

.toolbar-icon-button {
    background-color: var(--bg-surface);
}

.toolbar-icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    flex-shrink: 0;
}

/* One search form; mobile uses a disclosure toggle. */
.toolbar-search {
    margin-left: auto;
    width: 100%;
    max-width: 20rem;
    min-width: 0;
}

.toolbar-search > .mobile-search-toggle {
    display: none;
}

.toolbar-search > #search-form {
    position: relative;
    display: flex;
    max-width: none;
}

#search-input {
    flex: 1;
    min-width: 0;
    padding-right: 2.5rem;
}

/* Inset the 2rem button evenly within the 2.5rem search field. */
.search-submit {
    position: absolute;
    right: 0.25rem;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

#search-form:hover .search-submit,
#search-form:focus-within .search-submit {
    opacity: 1;
    pointer-events: auto;
}

@media (hover: none) {
    .search-submit {
        opacity: 1;
        pointer-events: auto;
    }
}

@media (width >= 768px) {
    .toolbar-search::details-content {
        content-visibility: visible;
    }
}

@media (width < 768px) {
    #toolbar .toolbar-row {
        position: relative;
        height: auto;
        min-height: 4rem;
        flex-wrap: wrap;
        gap: 0 0.5rem;
    }

    #toolbar .toolbar-actions {
        flex: 1 1 auto;
        gap: 0.25rem;
    }

    .toolbar-search {
        width: auto;
        max-width: none;
    }

    .toolbar-search > .mobile-search-toggle {
        display: inline-flex;
    }

    .toolbar-search:not([open]) > #search-form {
        display: none;
    }

    .toolbar-search[open] > #search-form {
        position: absolute;
        inset: 4rem var(--app-gutter) auto;
        width: auto;
    }

    #toolbar .toolbar-row:has(.toolbar-search[open]) {
        min-height: 7.25rem;
        padding-bottom: 3.25rem;
    }
}

.gallery-view-controls {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 0.125rem;
    margin-right: auto;
}

.gallery-view-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    width: 2rem;
    height: 2rem;
    padding: 0.25rem;
    border: 1px solid transparent;
}

.gallery-view-icon {
    width: 1.2rem;
    height: 1.2rem;
}

#toolbar details[open] > summary.toolbar-icon-button {
    border-color: #6366f1;
}

.gallery-view-controls:has(#gallery-view-masonry:checked) label[for='gallery-view-masonry'],
.gallery-view-controls:has(#gallery-view-grid:checked) label[for='gallery-view-grid'],
.gallery-view-controls:has(#gallery-view-list:checked) label[for='gallery-view-list'] {
    --icon-filter: brightness(0) saturate(100%) invert(42%) sepia(93%) saturate(1845%) hue-rotate(222deg) brightness(97%) contrast(96%);
}

.gallery-view-controls:has(#gallery-view-masonry:focus-visible) label[for='gallery-view-masonry'],
.gallery-view-controls:has(#gallery-view-grid:focus-visible) label[for='gallery-view-grid'],
.gallery-view-controls:has(#gallery-view-list:focus-visible) label[for='gallery-view-list'] {
    position: relative;
    z-index: 1;
    outline: 2px solid #6366f1;
    outline-offset: 2px;
}

.gallery-card-slot {
    position: relative;
    height: 4.25rem;
}

/* The slot holds the card's footprint; the meta is anchored to its bottom edge. */
.gallery-card-meta {
    position: absolute;
    inset: auto 0 0;
    box-sizing: border-box;
    min-height: 4.25rem;
    max-height: 4.25rem;
    padding: 0 0.625rem;
    font-size: 0.875rem;
    overflow: hidden;
    background-color: var(--bg-surface);
}

/* On hover the top edge rises over the image; the slot never reflows. */
.gallery-card:hover .gallery-card-meta,
.gallery-card:focus-within .gallery-card-meta {
    z-index: 10;
    max-height: 16rem;
}

.gallery-card-meta > .truncate {
    display: block;
    box-sizing: border-box;
    height: 2.5rem;
    line-height: 1.25rem;
    padding-block: 0.625rem;
    padding-right: 5rem;
}

/* A ribbon on the card's right edge marks where a click opens the inspector: shown while
   the pointer rests over the metadata, but not over the tags row or the actions, which
   keep their clicks to themselves. It floats over the image, so nothing reflows, and
   appears after a short delay so sweeping across the card doesn't flash it. */
.gallery-card::after {
    content: 'open inspector';
    visibility: hidden;
    position: absolute;
    top: 0.5rem;
    right: 0;
    z-index: 1;
    padding: 0 0.25rem;
    font-size: 0.75rem;
    line-height: 1rem;
    color: var(--text-primary);
    background-color: var(--bg-surface);
    pointer-events: none;
}

.gallery-card:has(.gallery-card-meta:hover):not(:has(.gallery-card-meta > .flex:hover, .card-actions:hover))::after {
    visibility: visible;
    transition: visibility 0s 0.12s;
}

.gallery-card-meta > .flex {
    gap: 0.25rem 0.5rem;
    margin-top: 0;
    padding-bottom: 0.625rem;
}

.gallery-card-meta > .flex:empty {
    padding-bottom: 0;
}

.gallery-card-meta .tag-badge {
    padding: 0;
}

.masonry-grid {
    --masonry-columns: 2;
    --masonry-gap: 0.75rem;

    display: grid;
    grid-template-columns: repeat(var(--masonry-columns), minmax(0, 1fr));
    gap: var(--masonry-gap);
    align-items: start;
}

.masonry-column {
    display: flex;
    flex-direction: column;
    gap: var(--masonry-gap);
}

@media (width >= 768px) {
    .masonry-grid {
        --masonry-columns: 3;
    }
}

@media (width >= 1024px) {
    .masonry-grid {
        --masonry-columns: 4;
    }
}

@media (width >= 1280px) {
    .masonry-grid {
        --masonry-columns: 5;
    }
}

.masonry-item {
    break-inside: avoid;
    display: block;
    align-self: start;
    width: 100%;
}

.masonry-item img {
    width: 100%;
    height: auto;
    display: block;
}

#pagination-controls {
    break-inside: avoid;
    grid-column: 1 / -1;
}

.gallery-status {
    break-inside: avoid;
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px dashed var(--border-color-light);
    border-radius: 0.75rem;
    background-color: var(--bg-surface);
    color: var(--text-muted);
    font-weight: 500;
    text-align: center;
}

.gallery-pagination-status {
    margin-top: 1.5rem;
    padding: 0.5rem 1rem;
}

#filter-bar:has(#gallery-view-grid:checked) ~ #photo-grid,
#filter-bar:has(#gallery-view-list:checked) ~ #photo-grid {
    grid-auto-rows: auto;
}

#filter-bar:has(#gallery-view-grid:checked) ~ #photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
    gap: 0.75rem;
}

#filter-bar:has(#gallery-view-list:checked) ~ #photo-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: stretch;
}

#filter-bar:has(#gallery-view-list:checked) ~ #photo-grid .masonry-column {
    width: 100%;
}

#filter-bar:has(#gallery-view-grid:checked) ~ #photo-grid .masonry-item,
#filter-bar:has(#gallery-view-list:checked) ~ #photo-grid .masonry-item {
    display: block;
    width: 100%;
    margin-bottom: 0;
    break-inside: auto;
    align-self: auto;
}

#filter-bar:has(#gallery-view-grid:checked) ~ #photo-grid #pagination-controls,
#filter-bar:has(#gallery-view-grid:checked) ~ #photo-grid .gallery-status {
    grid-column: 1 / -1;
}

#filter-bar:has(#gallery-view-grid:checked) ~ #photo-grid .gallery-card {
    height: 100%;
}

#filter-bar:has(#gallery-view-grid:checked) ~ #photo-grid .gallery-card-image {
    width: 100%;
    height: clamp(8rem, 16vw, 12rem);
    object-fit: cover;
}

#filter-bar:has(#gallery-view-grid:checked) ~ #photo-grid .gallery-card-meta .tag-badge {
    display: none;
}

#filter-bar:has(#gallery-view-list:checked) ~ #photo-grid .gallery-card {
    flex-direction: row;
    min-height: 8rem;
}

#filter-bar:has(#gallery-view-list:checked) ~ #photo-grid .gallery-card-image {
    flex: 0 0 12rem;
    width: 12rem;
    height: 8rem;
    object-fit: cover;
}

#filter-bar:has(#gallery-view-grid:checked) ~ #photo-grid .gallery-card-slot,
#filter-bar:has(#gallery-view-list:checked) ~ #photo-grid .gallery-card-slot {
    height: auto;
    min-width: 0;
}

#filter-bar:has(#gallery-view-grid:checked) ~ #photo-grid .gallery-card-meta,
#filter-bar:has(#gallery-view-list:checked) ~ #photo-grid .gallery-card-meta {
    position: relative;
    min-height: 0;
    max-height: none;
    overflow: visible;
}

@media (width < 640px) {
    #filter-bar:has(#gallery-view-list:checked) ~ #photo-grid .gallery-card-image {
        flex-basis: 7rem;
        width: 7rem;
    }
}

.gallery-main {
    --inspector-width: min(24rem, 42vw);

    position: relative;
    display: flex;
    width: 100vw;
    max-width: none;
    height: calc(100vh - 4rem);
    overflow: hidden;
}

.gallery-content {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-width: 0;
    height: 100%;
    overflow: hidden;
}

.layout {
    display: flex;
    flex: 1 1 auto;
    width: 100%;
    min-height: 0;
    overflow: hidden;
}

.toolbar-row {
    padding-inline: var(--app-gutter);
}

/* Keep each native disclosure's dropdown within the viewport. */
@supports (anchor-name: --toolbar-anchor) and (anchor-scope: --toolbar-anchor) and (position-try-fallbacks: flip-inline) {
    #toolbar details:has(> summary.toolbar-icon-button) {
        anchor-scope: --toolbar-anchor;
    }

    #toolbar summary.toolbar-icon-button {
        anchor-name: --toolbar-anchor;
    }

    #toolbar details > .dropdown-container {
        position: fixed;
        position-anchor: --toolbar-anchor;
        right: auto;
        left: clamp(1rem, anchor(left), max(1rem, calc(100vw - min(var(--dropdown-width), 100vw - 2rem) - 1rem)));
        top: anchor(bottom);
        max-width: calc(100vw - 2rem);
        max-height: calc(100vh - 5rem);
        overflow: auto;
        position-try-fallbacks: flip-inline;
    }

    #toolbar .dropdown-container.w-64 { --dropdown-width: 16rem; }
    #toolbar .dropdown-container.w-72 { --dropdown-width: 18rem; }
    #toolbar .dropdown-container.w-96 { --dropdown-width: 24rem; }
}

/* Main content area; padding scrolls with the filters and cards. */
.main-content {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.5rem var(--app-gutter) var(--app-gutter);
    overflow: auto;
    scrollbar-gutter: stable;
}

/* Commit the final content width at once, then slide the inspector over the
   freed space with a compositor-only transform. */
.gallery-main.inspector-open .gallery-content {
    margin-right: var(--inspector-width);
}

/* Inspector panel */
.inspector {
    font-size: 0.875rem;
    line-height: 1.25rem;
    position: absolute;
    top: 0;
    right: 0;
    width: var(--inspector-width);
    height: 100%;
    background-color: var(--bg-surface);
    border-left: 1px solid var(--border-color-light);
    overflow-x: hidden;
    overflow-y: auto;
    transform: translateX(100%);
    transition: transform 150ms ease-in-out;
}

.gallery-main.inspector-open .inspector {
    transform: none;
}

.inspector-inner {
    width: var(--inspector-width);
    min-width: 0;
    height: 100%;
    background-color: var(--bg-surface);
}

.inspector-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color-light);
}

.inspector-fields {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    gap: 1rem;
}

.inspector-fields > li {
    grid-column: 1 / -1;
}

.inspector-detail-divider {
    grid-column: 1 / -1;
    border: 0;
    border-top: 1px solid var(--border-color-light);
    margin: 0.25rem 0;
}

.inspector-detail-row {
    display: grid;
    grid-template-columns: subgrid;
    align-items: baseline;
    padding: 0.375rem 0.5rem;
}

.inspector-detail-row:nth-of-type(even) {
    background-color: var(--bg-surface-hover);
}

.inspector-detail-row > :first-child {
    text-align: right;
}

.inspector-detail-row > :last-child {
    min-width: 0;
    text-align: left;
    overflow-wrap: anywhere;
}

.inspector-body {
    min-width: 0;
    padding: 1rem;
    overflow-x: hidden;
    overflow-y: auto;
    overflow-wrap: anywhere;
}

@media (width < 768px) {
    .gallery-main.inspector-open .gallery-content {
        margin-right: 0;
    }

    .gallery-main .inspector {
        transition: none;
    }

    .inspector {
        transform: none;
        display: none;
        position: fixed;
        inset: auto 0 0;
        z-index: 51;
        height: 81vh;
        height: 81dvh;
        overflow: hidden;
    }

    .gallery-main.inspector-open .inspector {
        display: block;
        width: 100%;
        border-left-width: 0;
    }

    .inspector-inner {
        width: 100%;
    }
}

/* Show placeholder text when inspector content is empty */
#inspector-content:empty::after {
    content: 'Select an image to inspect it.';
    display: block;
    color: var(--text-muted);
    font-size: inherit;
    line-height: inherit;
}

.main-scroll {
    overflow: hidden;
}

/* Image loading placeholder — prevents flash of empty content when
   htmx outerHTML swaps in a fresh <img> whose URL hasn't loaded yet.
   The background colour shows through while the browser fetches the image. */
.gallery-card-image {
    background-color: var(--bg-surface-hover);
    object-fit: cover;
}

#photo-grid {
    position: relative;
    isolation: isolate;
}

/* Clip the rolling strip to real content without extending scrollHeight. */
.gallery-preview-surface {
    position: absolute;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: -1;
}

#thumbnail-background {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 0;
    pointer-events: none;
}

/* The canvas sits behind the cards; the <img> paints over its preview as the
   original streams in, so the card surfaces and image placeholder are clear. */
.gallery-previews-active #gallery-main {
    position: relative;
    z-index: 1;
}

.gallery-previews-active .gallery-card {
    background-color: transparent;
}

.gallery-previews-active .gallery-card-meta {
    background-color: var(--bg-surface);
}

.gallery-previews-active .gallery-card-image {
    background-color: transparent;
}

/* Refresh button → show a spinning indicator during the htmx request.
   The img stays in the layout via visibility: hidden so the button never
   resizes; the spinner is absolutely positioned over it. */
#inspector-header-refresh,
#inspector-header-delete,
#inspector-header-download,
#inspector-header-open-tab {
    position: relative;
}

#inspector-header-refresh:focus-visible,
#inspector-header-delete:focus-visible,
#inspector-header-download:focus-visible,
#inspector-header-open-tab:focus-visible {
    z-index: 1;
    outline: 2px solid var(--accent-indigo);
    outline-offset: 2px;
}

#inspector-header-refresh.htmx-request img,
#inspector-header-delete.htmx-request img,
[id^='inspector-name-save-'].htmx-request img {
    visibility: hidden;
}

#inspector-header-refresh.htmx-request::after,
#inspector-header-delete.htmx-request::after,
[id^='inspector-name-save-'].htmx-request::after {
    content: '';
    position: absolute;
    inset: 0;
    margin: auto;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent-indigo);
    border-radius: 50%;
    animation: booru-spin 0.6s linear infinite;
    box-sizing: border-box;
}

/* Delete button two-click confirmation — first click turns icon red */
#inspector-header-delete[data-confirmed] img {
    filter: brightness(0) saturate(100%) invert(27%) sepia(51%) saturate(2878%) hue-rotate(346deg) brightness(104%)
        contrast(97%) !important;
}

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

.thumbnail-progress:empty {
    display: none;
}

.thumbnail-progress-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.thumbnail-progress progress {
    width: 100%;
    height: 0.5rem;
    border: 0;
    border-radius: 9999px;
    overflow: hidden;
    appearance: none;
}

.thumbnail-progress progress::-webkit-progress-bar {
    background: var(--border-color-light);
    border-radius: 9999px;
}

.thumbnail-progress progress::-webkit-progress-value {
    background: var(--accent-indigo);
    border-radius: 9999px;
}

.thumbnail-progress progress::-moz-progress-bar {
    background: var(--accent-indigo);
    border-radius: 9999px;
}

.thumbnail-progress-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: var(--text-muted);
}
