:root {
    color-scheme: light;
    --bg: #f7f7f4;
    --surface: #ffffff;
    --surface-2: #eef3f1;
    --text: #202322;
    --muted: #64706b;
    --line: #d9dfdc;
    --accent: #1d766f;
    --accent-dark: #155853;
    --danger: #b53636;
    --warning: #9a6514;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
    color: var(--accent-dark);
}

img {
    max-width: 100%;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    min-height: 64px;
    padding: 0 28px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.brand {
    color: var(--text);
    font-weight: 750;
    text-decoration: none;
}

.topbar nav {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}

.topbar nav a {
    color: var(--muted);
    text-decoration: none;
}

.page {
    width: min(1120px, calc(100vw - 32px));
    margin: 28px auto 56px;
}

h1,
h2 {
    margin: 0;
    line-height: 1.15;
}

h1 {
    font-size: 2rem;
}

h2 {
    font-size: 1.1rem;
}

p {
    margin: 8px 0 0;
    color: var(--muted);
}

.auth-panel,
.panel,
.empty,
.card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.auth-panel {
    width: min(420px, 100%);
    margin: 48px auto;
    padding: 28px;
}

.hero,
.section-heading,
.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.hero {
    padding: 24px 0;
}

.panel,
.empty {
    padding: 20px;
    margin-bottom: 18px;
}

.columns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

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

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

.card {
    display: block;
    overflow: hidden;
    min-width: 0;
    min-height: 132px;
    padding: 18px;
    color: var(--text);
    text-decoration: none;
}

.card:hover {
    border-color: var(--accent);
}

.photo-card {
    display: grid;
    gap: 12px;
    min-height: 0;
    padding: 10px;
    align-content: start;
}

.photo-card small {
    overflow-wrap: anywhere;
}

.photo-card a {
    color: var(--text);
    text-decoration: none;
}

.album-cover {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    aspect-ratio: 2 / 1;
    object-fit: cover;
    border-radius: 6px;
    margin: 0 0 12px;
    background: var(--surface-2);
}

/* Cap album-listing cards so a single album doesn't expand to fill
   the whole row at gigantic size. Photo-grid cards are explicitly
   excluded so the photos pages keep filling their columns. */
.grid > .card:not(.photo-card) {
    max-width: 360px;
    width: 100%;
}

/* Belt-and-suspenders: ensure the cover image cannot exceed its card,
   even if a previously cached stylesheet is still in effect. */
.card .album-cover {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
}

.stack {
    display: grid;
    gap: 14px;
}

.compact {
    gap: 8px;
}

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 0.92rem;
    font-weight: 650;
}

input,
select {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--text);
    background: #fff;
    font: inherit;
}

textarea {
    width: 100%;
    min-height: 96px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--text);
    background: #fff;
    font: inherit;
    resize: vertical;
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
}

.check input {
    width: auto;
    min-height: 0;
}

button,
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    border: 0;
    border-radius: 6px;
    padding: 8px 14px;
    background: var(--accent);
    color: white;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

button:hover,
.button:hover {
    background: var(--accent-dark);
}

.secondary {
    border: 1px solid var(--line);
    background: var(--surface-2);
    color: var(--text);
}

.secondary:hover {
    border-color: var(--accent);
    background: #dfeae7;
}

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.disabled {
    opacity: 0.48;
    pointer-events: none;
}

.small {
    min-height: 32px;
    padding: 5px 10px;
    font-size: 0.9rem;
}

.danger {
    background: var(--danger);
}

.danger:hover {
    background: #8d2727;
}

.flash {
    margin-bottom: 14px;
    border: 1px solid #b9d8d5;
    border-radius: 8px;
    padding: 10px 12px;
    background: #e5f4f2;
}

.flash.error {
    border-color: #e1b4b4;
    background: #fae8e8;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border-radius: 999px;
    padding: 4px 10px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 700;
    white-space: nowrap;
}

.badge.warning {
    color: #fff;
    background: var(--warning);
}

.photo-placeholder,
.photo-stage {
    display: grid;
    place-items: center;
    min-height: 140px;
    margin-bottom: 12px;
    border-radius: 6px;
    background: linear-gradient(135deg, #dfeae7, #f3e9d6);
    color: var(--muted);
    font-weight: 800;
}

.photo-placeholder.deleted,
.photo-stage.deleted {
    background: #e4e1dc;
    color: #7d746b;
}

.video-stage {
    gap: 12px;
    padding: 24px;
    text-align: center;
}

.video-stage img {
    width: min(260px, 75%);
    height: auto;
}

.thumb {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    object-fit: cover;
    border-radius: 6px;
    margin: 0 0 10px;
    background: var(--surface-2);
}

/* Activity-feed thumbs override the cap below to render at 96px square. */

.photo-detail {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
    gap: 20px;
    min-width: 0;
}

.qr-panel {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 24px;
    align-items: start;
}

.qr-wrap {
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    background: #fff;
}

.qr-code {
    display: block;
    width: 100%;
    max-width: 252px;
    height: auto;
}

.inline-actions {
    display: grid;
    grid-template-columns: minmax(160px, 220px) auto;
    gap: 12px;
    align-items: end;
}

.photo-stage {
    max-width: 100%;
    margin: 0;
}

/* Only the placeholder/deleted state needs a min-height so the empty
   box doesn't collapse. The image stage sizes to its image. */
.photo-stage:not(.image-stage) {
    min-height: 420px;
}

.image-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    overflow: hidden;
    max-height: 72vh;
}

.image-stage img {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 72vh;
    object-fit: contain;
}

.photo-nav {
    display: grid;
    grid-template-columns: minmax(120px, auto) auto minmax(120px, auto);
    gap: 12px;
    align-items: center;
    justify-content: start;
    margin-bottom: 18px;
}

.metadata-panel {
    margin: 0;
    min-width: 0;
}

.action-stack {
    display: grid;
    gap: 10px;
    margin-top: 16px;
}

.album-picker,
.album-select-form,
.photo-edit-form,
.owner-form,
.danger-zone {
    display: grid;
    gap: 10px;
    margin-top: 16px;
}

.photo-edit-form,
.owner-form,
.danger-zone {
    border-top: 1px solid var(--line);
    padding-top: 16px;
}

.crop-form {
    display: grid;
    gap: 10px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

dl {
    margin: 0;
}

dl div {
    display: grid;
    gap: 3px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

dt {
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 750;
}

dd {
    margin: 0;
    overflow-wrap: anywhere;
}

code {
    font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.log-output {
    overflow-x: auto;
    margin: 16px 0 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #f3f6f5;
    color: var(--text);
    font: 0.9rem/1.45 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.inline-form,
.user-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(120px, 1fr)) auto auto auto;
    gap: 12px;
    align-items: end;
    margin-top: 16px;
}

.compact-form {
    grid-template-columns: minmax(140px, 240px) auto auto;
}

.upload-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(180px, 1fr)) auto;
    gap: 14px;
    align-items: end;
}

.upload-status {
    display: grid;
    gap: 8px;
    margin-top: 16px;
}

.upload-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(120px, 220px) 90px 150px;
    gap: 10px;
    align-items: center;
    border-top: 1px solid var(--line);
    padding-top: 8px;
}

.upload-name {
    overflow-wrap: anywhere;
}

.upload-row progress {
    width: 100%;
}

.upload-row.failed .upload-state {
    color: var(--danger);
}

.upload-row.duplicate .upload-state {
    color: #8b5a00;
}

.upload-action {
    display: flex;
    justify-content: flex-end;
}

.upload-row-action {
    min-height: 34px;
    padding: 7px 10px;
    font-size: 0.82rem;
    width: 100%;
}

.upload-state,
.upload-summary {
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
}

.upload-message {
    grid-column: 1 / -1;
    color: var(--muted);
}

.upload-error {
    border: 1px solid #e1b4b4;
    border-radius: 8px;
    padding: 10px 12px;
    background: #fae8e8;
    color: var(--danger);
}

.upload-failure-list {
    margin: 8px 0 0;
    padding-left: 20px;
}

.photo-workspace {
    align-items: start;
    margin-top: 18px;
}

.related-panel {
    margin-top: 18px;
}

.related-panel summary {
    cursor: pointer;
    font-weight: 800;
}

.related-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 12px;
    margin-top: 14px;
}

.related-card {
    display: grid;
    gap: 6px;
    color: var(--text);
    text-decoration: none;
}

.related-card span,
.related-card small {
    overflow-wrap: anywhere;
}

.related-thumb,
.related-placeholder {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--muted);
    font-weight: 800;
}

.related-thumb {
    display: block;
    height: auto;
    object-fit: cover;
}

.related-placeholder {
    display: grid;
    place-items: center;
}

.tag-form {
    grid-template-columns: minmax(160px, 1fr) auto;
    margin-top: 0;
    margin-bottom: 16px;
}

.tag-list,
.comment-list {
    display: grid;
    gap: 12px;
}

.tag-row,
.comment {
    border-top: 1px solid var(--line);
    padding-top: 12px;
}

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

.vote-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.selected {
    background: var(--accent-dark);
}

.comment header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 8px;
}

.comment-form {
    margin-bottom: 16px;
}

.activity-list {
    display: grid;
    gap: 14px;
}

.activity-item {
    display: grid;
    grid-template-columns: 104px minmax(0, 1fr);
    gap: 16px;
    align-items: start;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: var(--surface);
}

.activity-thumb {
    display: block;
    color: var(--text);
    text-decoration: none;
}

.activity-thumb .thumb,
.activity-thumb .photo-placeholder {
    width: 96px;
    height: 96px;
    max-width: none;
    min-height: 96px;
    margin: 0;
    object-fit: cover;
}

.activity-body {
    min-width: 0;
}

.activity-body header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}

.activity-body h2 a {
    color: var(--text);
    text-decoration: none;
}

.activity-body h2 a:hover {
    color: var(--accent-dark);
}

.table-wrap {
    overflow-x: auto;
}

.table-form {
    display: grid;
    grid-template-columns: minmax(160px, 1fr) auto;
    gap: 10px;
    align-items: end;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 0.84rem;
}

tr.attention {
    background: #fff7e8;
}

.reorder-list {
    list-style: none;
    margin: 16px 0 0;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    overflow: hidden;
}

.reorder-row {
    display: grid;
    grid-template-columns: 48px 64px 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
}

.reorder-row:last-child {
    border-bottom: none;
}

.reorder-page {
    font-variant-numeric: tabular-nums;
    color: var(--muted);
    text-align: right;
}

.reorder-thumb {
    width: 64px;
    height: 64px;
    object-fit: cover;
    border-radius: 4px;
    background: var(--surface-2);
}

.reorder-thumb.deleted {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 0.8rem;
}

.reorder-name {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

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

.reorder-name small {
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.reorder-actions {
    display: flex;
    gap: 4px;
}

.reorder-actions button {
    min-width: 32px;
}

@media (max-width: 760px) {
    .topbar,
    .hero,
    .section-heading,
    .panel-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .columns,
    .photo-detail,
    .photo-nav,
    .qr-panel,
    .inline-actions,
    .inline-form,
    .compact-form,
    .upload-form,
    .upload-row,
    .tag-form,
    .tag-row,
    .table-form,
    .user-row,
    .activity-item {
        grid-template-columns: 1fr;
    }

    .activity-thumb .thumb,
    .activity-thumb .photo-placeholder {
        width: 100%;
        height: auto;
        min-height: 160px;
    }

    .vote-controls {
        flex-wrap: wrap;
    }

    .page {
        width: min(100vw - 24px, 1120px);
        margin-top: 18px;
    }

    .upload-action {
        justify-content: flex-start;
    }

    .upload-row-action {
        width: auto;
    }
}
