:root {
    color-scheme: light;
    --bg: #f5f7f8;
    --panel: #ffffff;
    --ink: #222018;
    --muted: #657175;
    --line: #d9e0e3;
    --accent: #1f6f68;
    --accent-strong: #15524d;
    --ok: #16803c;
    --warning: #a26212;
    --danger: #b93030;
    --rating: #876600;
    --bar: #35433f;
    --bar-muted: #d4deda;
    --viewer-bg: #e2e8e6;
    --shadow: 0 16px 38px rgba(23, 32, 31, 0.12);
    --surface-soft: #e6ecee;
    --surface-alt: #e8eef0;
    --secondary-bg: #e5e7eb;
    --secondary-ink: #252a30;
    --accent-fill: #1f6f68;
    --accent-fill-hover: #15524d;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #171a1b;
    --panel: #222728;
    --ink: #e6ebea;
    --muted: #acb8b6;
    --line: #414c4a;
    --accent: #77cbbb;
    --accent-strong: #a0e0d3;
    --ok: #72d59a;
    --warning: #e7bd73;
    --danger: #f1a0a0;
    --rating: #e8c96b;
    --bar: #101615;
    --bar-muted: #c0ceca;
    --viewer-bg: #101716;
    --shadow: 0 16px 38px rgba(0, 0, 0, 0.24);
    --surface-soft: #2c3534;
    --surface-alt: #303a38;
    --secondary-bg: #35413e;
    --secondary-ink: #e6ebea;
    --accent-fill: #236e64;
    --accent-fill-hover: #2b8175;
}

.menu-item.theme-toggle {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    justify-content: center;
    padding: 9px;
    margin-left: auto;
    border: 0;
    background: transparent;
    cursor: pointer;
}
.theme-toggle[hidden] { display: none; }
.theme-toggle > span { display: flex; }
.theme-toggle + .topbar-user { margin-left: 0; }
:root:not([data-theme="dark"]) .theme-sun,
:root[data-theme="dark"] .theme-moon { display: none; }

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    letter-spacing: 0;
}

a {
    color: inherit;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px 24px;
    padding: 12px 24px;
    background: var(--bar);
    color: #fff;
    box-shadow: 0 6px 20px rgba(23, 32, 31, 0.2);
}

.brand {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    padding-right: 24px;
    border-right: 1px solid rgba(255, 255, 255, 0.18);
}

.brand-name {
    margin: 0;
    color: #a8ded2;
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 30px;
    font-style: italic;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0;
}

.menu {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 40px;
    padding: 9px 12px;
    border-radius: 8px;
    color: var(--bar-muted);
    text-decoration: none;
    font-weight: 700;
}

/* Menuepunkte sind meist Verweise. Als Knopf (Import, Anmelden) braechte der
   Browser sonst seine eigene helle Flaeche und Schrift mit – heller Text auf
   hellem Knopf. Deshalb hier dieselbe Flaeche wie bei den Verweisen. */
button.menu-item {
    border: 0;
    background: transparent;
    color: var(--bar-muted);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.menu-item.active,
.menu-item:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.menu-icon {
    display: inline-block;
    flex: 0 0 22px;
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
}

html[data-gallery-restoring="1"] .content { visibility: hidden; }

.content {
    min-width: 0;
    padding: 32px;
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 24px;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--accent-strong);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: 34px;
    line-height: 1.12;
}

.stats {
    min-width: 116px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
    text-align: right;
}

.stats strong,
.stats span {
    display: block;
}

.stats strong {
    font-size: 24px;
}

.stats span {
    color: var(--muted);
    font-size: 13px;
}

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

html.gallery-page { scrollbar-gutter: stable; }

[data-responsive-gallery] .image-card { min-width: 0; }

.gallery-search { margin: 0 0 24px; border-block: 1px solid var(--line); padding: 12px 0; }
.gallery-search > summary { cursor: pointer; font-weight: 700; color: var(--accent-strong); }
.gallery-search-form { margin-top: 16px; }
.gallery-search-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); gap: 16px; align-items: start; }
.gallery-search .field { min-width: 0; }
.gallery-search input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.gallery-search select { box-sizing: border-box; max-width: 100%; min-width: 0; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--ink); font: inherit; }
.gallery-tag-picker { min-width: 0; }
.gallery-tag-picker summary { cursor: pointer; font-size: 13px; font-weight: 700; }
.gallery-tag-picker input[type="search"] { width: 100%; margin: 8px 0; }
.gallery-tag-options { max-height: 170px; overflow-y: auto; }
.gallery-tag-options label { display: flex; align-items: flex-start; gap: 6px; padding: 4px 0; font-size: 13px; overflow-wrap: anywhere; }
.gallery-tag-options label[hidden] { display: none; }
.gallery-tag-options input { flex: none; accent-color: var(--accent); }
.gallery-tag-mode { margin: 0; padding: 0; border: 0; display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; }
.gallery-tag-mode legend { margin-bottom: 8px; color: var(--muted); font-weight: 700; }
.gallery-tag-mode input { accent-color: var(--accent); }
.gallery-search-actions { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-top: 14px; }
.gallery-search-actions .field { flex: 0 1 280px; }
.gallery-saved-searches { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 2px; }
.gallery-rating-form { display: flex; align-items: center; gap: 4px; width: 100%; max-width: 164px; min-height: 28px; margin: 0; }
.gallery-rating-stars,
.gallery-rating-display { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); min-width: 0; flex: 1; }
.gallery-rating-display { width: 100%; max-width: 140px; }
.gallery-rating-star,
.gallery-rating-clear { display: inline-flex; align-items: center; justify-content: center; min-width: 0; height: 28px; padding: 0; border: 0; border-radius: 3px; background: transparent; color: var(--muted); cursor: pointer; }
.gallery-rating-star .menu-icon,
.gallery-rating-clear .menu-icon { width: 16px; height: 16px; flex: 0 1 16px; }
.gallery-rating-star.is-filled { color: var(--rating); }
.gallery-rating-star.is-filled .menu-icon { fill: currentColor; }
.gallery-rating-star:hover { color: var(--rating); }
.gallery-rating-display .gallery-rating-star { cursor: default; }
.gallery-rating-clear { flex: 0 0 20px; }
.gallery-rating-clear:hover:not(:disabled) { color: var(--accent-strong); }
.gallery-rating-clear:disabled { opacity: .35; cursor: default; }
.gallery-rating-star:focus-visible,
.gallery-rating-clear:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.gallery-rating-form[aria-busy="true"] { opacity: .65; }
.gallery-rating-status { height: 16px; margin: 0; overflow: hidden; color: var(--muted); font-size: 11px; line-height: 16px; text-overflow: ellipsis; white-space: nowrap; }
.gallery-rating-status[data-state="success"] { color: var(--ok); }
.gallery-rating-status[data-state="error"] { color: var(--danger); }

.notice {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.notice strong {
    font-size: 14px;
}

.notice span {
    color: var(--muted);
    font-size: 13px;
}

.notice.success {
    border-color: rgba(22, 128, 60, 0.25);
}

.notice.success strong {
    color: var(--ok);
}

.notice.warning {
    border-color: rgba(162, 98, 18, 0.3);
}

.notice.warning strong {
    color: var(--warning);
}

.image-card {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.image-link {
    position: relative;
    display: block;
    aspect-ratio: 1 / 1;
    background: var(--surface-soft);
}

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

.gallery-preview {
    width: min(1100px, calc(100% - 24px));
    height: min(820px, calc(100vh - 24px));
    height: min(820px, calc(100dvh - 24px));
    max-width: none;
    max-height: none;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--ink);
}
.gallery-preview[open] { display: grid; grid-template-rows: auto minmax(0, 1fr); }
html.gallery-preview-open { overflow: hidden; }
.gallery-preview::backdrop { background: rgb(0 0 0 / 65%); }
@keyframes gallery-preview-resize {
    from {
        opacity: 0;
        width: min(320px, calc(100% - 24px));
        height: min(240px, calc(100vh - 24px));
        height: min(240px, calc(100dvh - 24px));
    }
    to {
        opacity: 1;
        width: min(1100px, calc(100% - 24px));
        height: min(820px, calc(100vh - 24px));
        height: min(820px, calc(100dvh - 24px));
    }
}
@keyframes gallery-preview-backdrop-enter {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes gallery-preview-resize-out {
    from {
        opacity: var(--preview-close-opacity, 1);
        width: var(--preview-close-width);
        height: var(--preview-close-height);
    }
    to {
        opacity: 0;
        width: min(320px, calc(100% - 24px));
        height: min(240px, calc(100vh - 24px));
        height: min(240px, calc(100dvh - 24px));
    }
}
@keyframes gallery-preview-backdrop-exit {
    from { opacity: var(--preview-backdrop-opacity, 1); }
    to { opacity: 0; }
}
@media (prefers-reduced-motion: no-preference) {
    .gallery-preview[open] { animation: gallery-preview-resize 500ms ease-out; }
    .gallery-preview[open]::backdrop { animation: gallery-preview-backdrop-enter 500ms ease-out; }
    .gallery-preview[open].is-closing { animation: gallery-preview-resize-out 500ms ease-in-out forwards; }
    .gallery-preview[open].is-closing::backdrop { animation: gallery-preview-backdrop-exit 500ms ease-in-out forwards; }
}
.gallery-preview-header { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.gallery-preview-header h2 { flex: 1; min-width: 0; margin: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gallery-preview-header .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; flex: none; text-decoration: none; }
.gallery-preview-header .menu-icon { width: 18px; height: 18px; flex-basis: 18px; }
.gallery-preview-close { width: 36px; height: 36px; padding: 8px; }
.gallery-preview-navigation,
.viewer-nav { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.gallery-preview-step,
.viewer-nav-link {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 56px;
    padding: 0;
    border: 0;
    border-radius: 0;
    appearance: none;
    background: transparent;
    box-shadow: none;
    color: #fff;
    cursor: pointer;
    pointer-events: auto;
}
.gallery-preview-step .menu-icon,
.viewer-nav-link .menu-icon { display: block; flex: 0 0 30px; width: 30px; height: 30px; margin: 0; }
.gallery-preview-step:disabled,
.viewer-nav-link.disabled { opacity: .45; cursor: default; }
.gallery-preview-step:focus-visible,
.viewer-nav-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#gallery-preview-previous, #viewer-previous { left: 8px; }
#gallery-preview-next, #viewer-next { right: 8px; }
.gallery-preview-stage { position: relative; min-height: 0; min-width: 0; background: var(--viewer-bg); }
.gallery-preview-image { position: absolute; inset: 0; display: block; width: 100%; height: 100%; object-fit: contain; background: var(--viewer-bg); }
@keyframes gallery-preview-crossfade {
    from { opacity: 0; }
    to { opacity: 1; }
}
@media (prefers-reduced-motion: no-preference) {
    .gallery-preview-image.is-crossfading { z-index: 1; animation: gallery-preview-crossfade 180ms ease-in-out both; }
}
.gallery-preview-status { z-index: 1; }
.gallery-preview-image[hidden], .gallery-preview-status[hidden] { display: none; }
.gallery-preview-status { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: 20px 64px; text-align: center; color: var(--ink); font-size: 14px; }

.image-meta {
    display: grid;
    gap: 4px;
    padding: 10px 12px 12px;
}

.image-meta strong {
    overflow: hidden;
    font-size: 14px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.image-meta span {
    color: var(--muted);
    font-size: 12px;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-top: 28px;
}

.pagination a,
.pagination span {
    min-height: 40px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    text-decoration: none;
    font-weight: 700;
}

.pagination span {
    color: var(--muted);
    font-weight: 600;
}

.pagination a:hover {
    border-color: var(--accent);
    color: var(--accent-strong);
}

.pagination a.disabled {
    pointer-events: none;
    opacity: 0.45;
}

.gallery-pagination {
    gap: 8px;
    flex-wrap: wrap;
}

.gallery-pagination .gallery-page-step {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 40px;
    height: 40px;
    padding: 8px;
    background: transparent;
}

.gallery-pagination .gallery-page-step.disabled { opacity: .45; }
.gallery-page-state { white-space: nowrap; }

@media (max-width: 600px) {
    .gallery-pagination {
        display: grid;
        grid-template-columns: repeat(6, minmax(0, 1fr));
        width: min(100%, 360px);
        margin-inline: auto;
        gap: 8px 6px;
    }
    .gallery-pagination .gallery-page-step { grid-row: 1; min-width: 0; padding: 8px 2px; gap: 2px; font-size: 12px; }
    .gallery-pagination .menu-icon { width: 16px; height: 16px; flex-basis: 16px; }
    .gallery-pagination .gallery-page-state { grid-row: 2; grid-column: 1 / -1; text-align: center; }
}

.empty-state {
    padding: 28px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.empty-state h2 {
    margin: 0 0 8px;
}

.empty-state p {
    margin: 0;
    color: var(--muted);
}

code {
    padding: 2px 5px;
    border-radius: 5px;
    background: var(--surface-alt);
}

/* Import-Button und Fortschritt in der Kopfzeile */
.import-trigger {
    border: 0;
    background: transparent;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.import-trigger:disabled {
    cursor: default;
    opacity: 0.55;
}

.import-trigger .menu-label {
    flex: 1;
}

.import-count {
    min-width: 36px;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
}

.import-panel {
    padding: 12px 24px 14px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}

.import-bar {
    height: 6px;
    overflow: hidden;
    border-radius: 999px;
    background: var(--surface-soft);
}

.import-bar-fill {
    display: block;
    width: 0;
    height: 100%;
    border-radius: 999px;
    background: var(--accent-fill);
    transition: width 0.2s ease;
}

.import-status {
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

/* --- Benutzer und Anmeldung in der Kopfzeile --- */

.topbar-user {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-left: auto;
}

.topbar-title {
    margin: 0;
    color: var(--bar-muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.user-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    padding: 7px 11px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.08);
    font-size: 14px;
}

.role-badge {
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--accent-fill);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.auth-form {
    display: grid;
    gap: 10px;
}

.auth-form label {
    display: grid;
    gap: 5px;
    color: var(--bar-muted);
    font-size: 12px;
    font-weight: 700;
}

/* Anmeldung und Ersteinrichtung sitzen kompakt in der Kopfzeile. */
.topbar-auth {
    align-items: flex-end;
}

.topbar-auth .topbar-title {
    align-self: center;
}

.topbar-auth .auth-form {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 10px;
}

.topbar-auth .auth-form label {
    gap: 3px;
    font-size: 11px;
}

.topbar-auth .auth-form input {
    width: 170px;
}

.auth-form input {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 7px;
    background: rgba(0, 0, 0, 0.28);
    color: #fff;
    font: inherit;
    font-size: 14px;
    font-weight: 400;
}

.auth-form input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

/* Anmelde-Dropdown: Knopf in der Kopfzeile, Formular im Popover darunter.
   Die Lage setzt js/login.js vor dem Oeffnen; ohne JavaScript erscheint das
   Feld an seiner Stelle im Dokument, bleibt aber bedienbar. */
.login-popup {
    position: fixed;
    inset: auto;
    box-sizing: border-box;
    width: min(280px, calc(100vw - 32px));
    max-height: calc(100dvh - 96px);
    margin: 0;
    overflow: auto;
    padding: 16px 18px 18px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--ink);
    box-shadow: var(--shadow);
}

.login-popup-title {
    margin: 0 0 12px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

/* Das Formular steht auf hellem Grund und erbt deshalb nicht die Farben der
   dunklen Kopfzeile. */
.login-popup .auth-form {
    display: grid;
    gap: 10px;
}

.login-popup .auth-form label {
    color: var(--muted);
}

.login-popup .auth-form input {
    width: 100%;
    border-color: var(--line);
    background: var(--bg);
    color: var(--ink);
}

.login-popup .auth-form .btn {
    justify-self: start;
}

.form-error {
    color: #f0a1a1;
    font-size: 12px;
}

/* --- Formulare und Tabellen im Inhaltsbereich --- */

.panel {
    margin-bottom: 28px;
    padding: 22px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.panel-title {
    margin: 0 0 18px;
    font-size: 18px;
}

.form-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: flex-end;
}

.field {
    display: grid;
    flex: 1 1 180px;
    gap: 6px;
    min-width: 160px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.field input,
.field select,
.field textarea {
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--bg);
    color: var(--ink);
    font: inherit;
    font-size: 15px;
    font-weight: 400;
}

.field textarea {
    resize: vertical;
}

.user-edit-input {
    box-sizing: border-box;
    width: 100%;
    min-width: 210px;
    min-height: 40px;
    padding: 8px 11px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--bg);
    color: var(--ink);
    font: inherit;
    font-size: 14px;
}
.user-edit-actions > .inline-form { margin-bottom: 8px; }

.user-edit-input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.form-hint {
    margin: 18px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

.btn {
    padding: 10px 18px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: transparent;
    color: var(--accent-strong);
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.btn:hover:not(:disabled) {
    border-color: var(--accent);
}

.btn:focus-visible,
.tag-suggestion:focus-visible,
.tag-chip-edit:focus-visible,
.tag-chip-remove:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.topbar .btn {
    border-color: var(--bar-muted);
    color: var(--bar-muted);
}

.btn-small {
    padding: 7px 13px;
    font-size: 13px;
}

.inline-form {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 0;
}

.inline-form select {
    padding: 7px 9px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--bg);
    color: var(--ink);
    font: inherit;
    font-size: 13px;
}

.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.table-wrapper table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.table-wrapper th,
.table-wrapper td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.table-wrapper th {
    background: var(--bg);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.05em;
    white-space: nowrap;
    text-transform: uppercase;
}

.table-wrapper tbody tr:last-child td {
    border-bottom: 0;
}

.backup-table { border-radius: 8px; box-shadow: none; }
.backup-table th { letter-spacing: 0; }
.backup-table td:not(.backup-name) { white-space: nowrap; }
.backup-name { overflow-wrap: anywhere; }
.backup-actions { display: flex; align-items: center; gap: 8px; }
.backup-actions .btn,
[data-backup-create] .btn,
[data-backup-upload] .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; text-decoration: none; }
[data-backup-create] .btn[aria-busy="true"]::before,
[data-backup-upload] .btn[aria-busy="true"]::before,
.caption-actions .btn[aria-busy="true"]::before {
    content: "";
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
    box-sizing: border-box;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: button-spin 0.8s linear infinite;
}
@keyframes button-spin {
    to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
    [data-backup-create] .btn[aria-busy="true"]::before,
    [data-backup-upload] .btn[aria-busy="true"]::before,
    .caption-actions .btn[aria-busy="true"]::before { animation: none; }
}
.caption-actions .btn[aria-busy="true"] { display: inline-flex; align-items: center; gap: 8px; }
.caption-status { margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.caption-status[data-state="error"] { color: var(--danger); }
.backup-dialog {
    width: min(440px, calc(100% - 32px));
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--ink);
}
.backup-dialog::backdrop { background: rgb(0 0 0 / 45%); }
.backup-dialog h2 { margin-top: 0; font-size: 20px; }
.backup-dialog .backup-actions { justify-content: flex-end; flex-wrap: wrap; }

.tag {
    margin-left: 6px;
    padding: 2px 9px;
    border-radius: 999px;
    background: var(--bg);
    color: var(--accent-strong);
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.muted {
    color: var(--muted);
    font-size: 13px;
}

/* --- Vollbildansicht --- */

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

.viewer-main { min-width: 0; }

/* Titel und Kommentar ueber dem Bild; fuer alle Rollen sichtbar, gesetzt
   werden sie im Seitenbereich von einem Administrator. */
.viewer-heading {
    display: grid;
    gap: 4px;
    margin: 0 0 12px;
}
[data-image-caption][hidden] { display: none; }
[data-image-comment] { white-space: pre-line; }

.viewer-caption {
    margin: 0;
    color: var(--ink);
    font-size: 19px;
    font-weight: 700;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.viewer-comment {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.viewer-metadata {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 6px 20px;
    margin: 12px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.6;
    overflow-wrap: anywhere;
}

.viewer-heading,
.viewer-metadata {
    margin-inline-start: var(--viewer-image-offset, 56px);
    width: var(--viewer-image-width, calc(100% - 112px));
    max-width: calc(100% - var(--viewer-image-offset, 56px));
    text-align: left;
}

.viewer-metadata > div { display: flex; flex-wrap: wrap; gap: 0 5px; }
.viewer-metadata dt { font-weight: 400; }
.viewer-metadata dt::after { content: ':'; }
.viewer-metadata dd { margin: 0; }
.viewer-metadata a { color: inherit; }

.viewer-stage {
    position: relative;
    display: grid;
    min-height: 320px;
    margin: 0;
    padding: 16px 56px;
    place-items: center;
    border-radius: 12px;
    background: var(--viewer-bg);
    box-shadow: var(--shadow);
}

.viewer-stage img {
    max-width: 100%;
    max-height: 74vh;
    border-radius: 6px;
    object-fit: contain;
}

.viewer-title {
    margin: 0;
    font-size: 22px;
    word-break: break-word;
}

.viewer-side {
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

/* Aufklappbare Gruppen der Seitenleiste: eine Ueberschrift, ein Zustand. */
.panel-group {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

.panel-group:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
}

.panel-summary {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    list-style: none;
}

.viewer-side .panel-summary {
    padding: 9px 12px;
    border-radius: 4px;
    background: color-mix(in srgb, var(--accent) 7%, var(--panel));
    overflow-wrap: anywhere;
}

.viewer-side .panel-summary:hover {
    background: color-mix(in srgb, var(--accent) 12%, var(--panel));
}

/* Das Standard-Dreieck raus; es wird durch das Zeichen davor ersetzt. */
.panel-summary::-webkit-details-marker {
    display: none;
}

.panel-summary::before {
    flex-shrink: 0;
    width: 0;
    height: 0;
    border-top: 4px solid transparent;
    border-bottom: 4px solid transparent;
    border-left: 5px solid currentColor;
    color: var(--muted);
    content: '';
    transition: transform 0.15s ease;
}

.panel-group[open] > .panel-summary::before {
    transform: rotate(90deg);
}

.panel-summary:hover {
    color: var(--accent);
}

.panel-summary:focus-visible {
    border-radius: 4px;
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Etwas Luft zwischen Ueberschrift und Inhalt. */
.panel-group > .panel-summary + * {
    margin-top: 14px;
}

.panel-subtitle {
    margin: 24px 0 10px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.facts {
    display: grid;
    gap: 12px;
    margin: 0;
}

.facts div {
    display: grid;
    gap: 2px;
}

.facts dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.facts dd {
    margin: 0;
    font-size: 14px;
    word-break: break-word;
}

.viewer-nav-link {
    color: var(--ink);
    text-decoration: none;
}

.viewer-original {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 3;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    color: #fff;
    text-decoration: none;
}

.viewer-original .menu-icon {
    width: 22px;
    height: 22px;
    flex: 0 0 22px;
    filter: drop-shadow(0 1px 2px #000);
}

.viewer-original:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* --- Tags --- */

.face-canvas { position: relative; max-width: 100%; line-height: 0; }
.face-canvas > img { display: block; width: auto; height: auto; }
.face-box { position: absolute; border: 2px solid #ffd166; line-height: 1; }
.face-box.assigned { border-color: #46d58b; }
.face-box span { display: inline-block; padding: 3px; background: #101716; color: white; font-size: 12px; }
.face-box:focus-visible { outline: 3px solid white; outline-offset: 3px; }
.recognition { margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--line); }
.recognition-toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: 12px 24px; }
.recognition-controls { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin: 12px 0; }
.recognition-controls input:not([type="hidden"]):not([type="checkbox"]), .recognition-controls select {
    min-width: 0; max-width: 100%; padding: 9px; border: 1px solid var(--line); border-radius: 6px;
    background: var(--panel); color: var(--ink); font: inherit;
}
.recognition-controls input[type="checkbox"] { width: 18px; height: 18px; vertical-align: middle; accent-color: var(--accent); }
.recognition .btn { max-width: 100%; white-space: normal; }
.recognition .btn:disabled { opacity: .5; cursor: not-allowed; }
.recognition .secondary { background: transparent; color: var(--muted); }
.recognition-search .recognition-toolbar,
.recognition-search .recognition-controls { flex-direction: column; align-items: stretch; }
.recognition-search .btn { max-width: 100%; white-space: normal; }
.recognition-search .btn:disabled { opacity: .5; cursor: not-allowed; }
.recognition-search .secondary { background: transparent; color: var(--muted); }
.viewer-side .face-assignment { flex-direction: column; align-items: stretch; }
.viewer-side .face-assignment .btn { max-width: 100%; white-space: normal; }
.face-assignment { padding: 10px 0; border-bottom: 1px solid var(--line); }
.face-assignment:target { outline: 2px solid var(--accent); outline-offset: 5px; }
.recognition-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); gap: 16px; }
.recognition-candidate { min-width: 0; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--panel); }
.recognition-candidate label { display: block; cursor: pointer; }
.recognition-candidate img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: contain; background: var(--surface-soft); }
.candidate-choice { display: block; padding: 10px; font-size: 13px; overflow-wrap: anywhere; }
.candidate-time { margin: 0; padding: 0 10px 8px; color: var(--muted); font-size: 12px; }
.candidate-meta { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding: 0 10px 12px; font-size: 12px; }

/* Tooltip mit den zugewiesenen Tags: erscheint beim Ueberfahren der Kachel. */
.candidate-image { position: relative; display: block; }

/* Personensuche: markiert das gefundene Gesicht in der Vorschlagskachel. */
.candidate-face {
    position: absolute;
    z-index: 1;
    border: 2px solid #ffd166;
    box-shadow: 0 0 0 1px rgba(16, 23, 22, 0.5);
    pointer-events: none;
}

.candidate-tags {
    position: absolute;
    z-index: 2;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-height: 100%;
    padding: 7px 9px;
    overflow: hidden;
    background: rgba(23, 32, 31, 0.88);
    opacity: 0;
    transition: opacity 0.12s ease;
    pointer-events: none;
}

.recognition-candidate:hover .candidate-tags,
.recognition-candidate:focus-within .candidate-tags {
    opacity: 1;
}

.candidate-tag {
    max-width: 100%;
    overflow: hidden;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.candidate-tags-empty {
    color: #cfd8d6;
    font-size: 11px;
    font-style: italic;
}
.recognition .notice { overflow-wrap: anywhere; }
.recognition h3 { overflow-wrap: anywhere; }

.tag-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 18px;
    padding: 0;
    list-style: none;
}

.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 4px 4px 11px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: transparent;
    color: var(--accent-strong);
    font-size: 13px;
    font-weight: 700;
}

.tag-chip:hover,
.tag-chip:focus-within { border-color: var(--accent); }

.tag-chip-name {
    max-width: 170px;
    overflow: hidden;
    color: inherit;
    text-decoration: none;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tag-chip-form {
    display: inline-flex;
    margin: 0;
}

/* Bearbeiten und Entfernen sitzen als gleich grosse Knoepfe im Chip. */
.tag-chip-edit,
.tag-chip-remove {
    display: grid;
    width: 20px;
    height: 20px;
    padding: 0;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
}

.tag-chip-edit {
    text-decoration: none;
}

.tag-chip-edit:hover {
    color: var(--accent);
}

.tag-chip-remove:hover {
    color: var(--danger);
}

/* Tag-Vorschlaege: ein Klick auf den Vorschlag ordnet den Tag zu. Die gestrichelte
   Umrandung unterscheidet sie von den bereits vergebenen Tags. */
.tag-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 12px;
    padding: 0;
    list-style: none;
}

.tag-suggestion-form {
    display: inline-flex;
    margin: 0;
}

.tag-suggestion {
    padding: 5px 12px;
    border: 1px dashed var(--line);
    border-radius: 6px;
    background: transparent;
    color: var(--accent-strong);
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
}

.tag-suggestion:hover,
.tag-suggestion:focus-visible {
    border-color: var(--accent);
}

.tag-suggest-form {
    margin: 0 0 6px;
}

/* Antwort der Cloud-Bestimmung: reiner Text, zum Markieren und Kopieren. */
.ki-info-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 20px;
    cursor: pointer;
    vertical-align: middle;
}

.ki-info-button:hover,
.ki-info-button:focus-visible { color: var(--accent-strong); }

.ki-info-popup {
    box-sizing: border-box;
    width: min(360px, calc(100vw - 32px));
    max-height: calc(100dvh - 32px);
    overflow: auto;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--ink);
    box-shadow: var(--shadow);
    line-height: 1.6;
}

.ki-info-popup p { margin: 0 0 12px; }
.ki-info-close {
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--accent-strong);
    font: inherit;
    text-decoration: underline;
    cursor: pointer;
}

.ki-answer {
    margin: 0 0 12px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: 8px;
    background: var(--panel);
}

.ki-answer-text {
    margin: 0;
    font-size: 14px;
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.ki-answer-meta {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 11px;
}

/* Belegstellen aus der Websuche: nur die Domain, der Titel steht im Tooltip. */
.ki-sources {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
    margin: 10px 0 0;
    padding: 0;
    list-style: none;
    font-size: 11px;
}

.ki-sources a {
    color: var(--accent);
    text-decoration: none;
    border-bottom: 1px dotted currentColor;
}

.ki-sources a:hover,
.ki-sources a:focus-visible {
    border-bottom-style: solid;
}

.tag-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    margin: 0 0 4px;
}

.tag-form .btn {
    flex: 0 0 auto;
}

.tag-role-form { flex-wrap: wrap; align-items: center; }
.tag-role-descendants {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
    min-width: 0;
}
.tag-role-descendants input { flex: 0 0 18px; width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }

/* Recht eines Bildes: nur Administratoren, wirkt ausschliesslich in der Galerie. */
.recht-form {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    margin: 0 0 4px;
}

.recht-form .field {
    flex: 0 0 auto;
    min-width: 170px;
}

.recht-form .btn {
    flex: 0 0 auto;
}

/* Rollenfilter der Bildlisten; nur fuer Administratoren sichtbar. */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
    margin: 0 0 18px;
}

.filter-bar .field {
    flex: 0 0 auto;
    min-width: 170px;
}

/* Titel und Kommentar im Seitenbereich: Felder untereinander. */
.caption-form {
    display: grid;
    gap: 10px;
    margin: 0 0 4px;
}

/* Beschreiben und Speichern stehen nebeneinander, Speichern rechts. */
.caption-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.caption-form .btn {
    justify-self: start;
}

/* Tag-Galerie: Auswahl der Tags */

/* Tag-Auswahl links, Bilder rechts daneben. */
.tag-galerie {
    display: grid;
    grid-template-columns: minmax(0, 300px) minmax(0, 1fr);
    gap: 22px;
    align-items: start;
}

.tag-picker {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.tag-picker-titel {
    margin: 0;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
    font-weight: 700;
}

.tag-picker-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin: 0;
    padding: 14px 16px;
    list-style: none;
}

.tag-picker-hint {
    padding: 0 16px 14px;
}

/* Baumordnung: Jede Ebene rueckt den ganzen Eintrag ein, eine Baummarkierung
   (└ bzw. ├) zeigt die Stellung unter den Geschwistern. Rahmen und Hintergrund
   vertiefen sich dezent mit der Ebene – Ebene 0 bleibt wie bisher. */
.tag-picker-entry {
    --spalte: 14px;
    margin-left: calc(var(--tiefe, 0) * var(--spalte));
}

.tag-picker-link {
    display: flex;
    align-items: center;
    gap: 7px;
    width: 100%;
    padding: 5px 11px;
    border: 1px solid color-mix(in srgb, var(--accent) calc(var(--tiefe, 0) * 14%), var(--line));
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent) calc(var(--tiefe, 0) * 3%), var(--panel));
    color: inherit;
    font-size: 13px;
    text-decoration: none;
}

.tag-picker-link:hover {
    border-color: var(--accent);
}

.tag-picker-link.is-active {
    border-color: var(--accent);
    background: transparent;
    color: var(--accent-strong);
}

.tag-picker-branch {
    flex: none;
    width: 12px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1;
    text-align: center;
}

.tag-picker-link.is-active .tag-picker-branch {
    color: var(--accent-strong);
}

.tag-picker-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tag-picker-count {
    flex: none;
    padding: 1px 7px;
    border-radius: 999px;
    background: rgba(23, 32, 31, 0.08);
    font-size: 11px;
    font-weight: 700;
}

.tag-picker-link.is-active .tag-picker-count {
    background: transparent;
}

/* Modul "Tags bearbeiten" */
html:has([data-tag-tree]) {
    scrollbar-gutter: stable;
}

.tag-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: flex-end;
    margin: 0 0 20px;
}

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

.tag-table {
    width: 100%;
    min-width: 480px;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 14px;
}

.tag-table .tag-role-column {
    width: 216px;
}

.tag-inline-role {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 0;
}

.tag-inline-role select {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    height: 32px;
    padding: 4px 6px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--bg);
    color: var(--ink);
    font: inherit;
    font-size: 13px;
}

.tag-inline-role select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.tag-inline-role-save.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 32px;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 5px;
}

.tag-inline-role-save .menu-icon {
    width: 16px;
    height: 16px;
    flex: 0 0 16px;
}

.tag-table th,
.tag-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

.tag-table thead th {
    color: var(--muted);
    font-size: 12px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.tag-table tbody tr:hover {
    background: rgba(31, 111, 104, 0.05);
}

.tag-table th.tag-tree {
    white-space: normal;
    overflow-wrap: anywhere;
}

/* Tiefe Zweige behalten auch auf schmalen Ansichten Platz fuer den Namen. */
.tag-table .tag-tree > .tag-tree-content {
    padding-left: min(calc(var(--tiefe, 0) * 32px), 50%);
}

.tag-tree-toggle,
.tag-tree-spacer {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    margin-right: 4px;
    vertical-align: middle;
}

.tag-tree-toggle {
    padding: 0;
    border: 0;
    border-radius: 4px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}

.tag-tree-toggle[hidden] {
    display: none;
}

.tag-tree-toggle:hover {
    color: var(--accent);
}

.tag-tree-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.tag-tree-toggle .menu-icon {
    transition: transform 250ms cubic-bezier(0.16, 1, 0.3, 1);
}

.tag-tree-toggle[aria-expanded="true"] .menu-icon {
    transform: rotate(90deg);
}

@media (prefers-reduced-motion: reduce) {
    .tag-tree-toggle .menu-icon {
        transition: none;
    }
}

.tag-links {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0 0 18px;
    padding: 0;
    list-style: none;
}

/* Anzahl hinter dem Namen, verlinkt in die Tag-Galerie. */
.tag-count {
    margin-left: 7px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    text-decoration: none;
}

.tag-count:hover,
.tag-count:focus-visible {
    color: var(--accent);
    text-decoration: underline;
}

/* Virtueller Tag "nicht zugeordnet": fasst die Tags ohne Ober- und ohne
   Unterbegriff zusammen. Reine Ueberschrift in der Liste, kein echter Tag –
   deshalb ohne Bearbeitungslink und mit zurueckhaltender Anzahl. */
.tag-group-row th {
    background: rgba(23, 32, 31, 0.045);
}

.tag-group-name {
    color: var(--muted);
    font-style: italic;
    font-weight: 700;
}

.tag-count.tag-count-quiet {
    color: var(--muted);
    font-weight: 700;
    text-decoration: none;
}

.tag-detail .panel-title {
    margin-top: 26px;
}

.tag-detail { max-width: 800px; }

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

.tag-editor-form > .combo-label { grid-column: 1; margin: 0; }
.tag-editor-form > input:not([type="hidden"]),
.tag-editor-form > select,
.tag-editor-form > .combo { grid-column: 2; min-width: 0; }
.tag-editor-form > input:not([type="hidden"]),
.tag-editor-form > select,
.tag-editor-form .combo-input,
.tag-create-field > input,
.tag-create-field > select,
.tag-create-field .combo-input,
.tag-filter > input[type="text"] {
    width: 100%;
    height: 40px;
    box-sizing: border-box;
    padding: 8px 11px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--bg);
    color: var(--ink);
    font: inherit;
    font-size: 14px;
}
.tag-filter > input[type="text"] { width: auto; max-width: 100%; min-width: 0; }
.tag-filter > .btn { min-height: 40px; box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; }
.tag-editor-form > .btn { grid-column: 3; grid-row: 1; width: 100%; min-height: 40px; }
.tag-editor-form > .tag-role-descendants { grid-column: 2 / -1; grid-row: 2; }

@media (max-width: 640px) {
    .tag-editor-form { grid-template-columns: minmax(0, 1fr); gap: 8px; }
    .tag-editor-form > .combo-label,
    .tag-editor-form > input:not([type="hidden"]),
    .tag-editor-form > select,
    .tag-editor-form > .combo,
    .tag-editor-form > .tag-role-descendants,
    .tag-editor-form > .btn { grid-column: 1; grid-row: auto; }
}

.tag-create-form { flex-wrap: wrap; gap: 12px; }
.tag-create .tag-create-form { align-items: flex-end; }
.tag-create-field { flex: 1 1 180px; min-width: min(180px, 100%); }
.tag-create .tag-create-form > .btn { width: auto; min-height: 40px; }

@media (max-width: 480px) {
    .tag-create .tag-create-form > .btn { width: 100%; }
}

.tag-create {
    margin: 0 0 22px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.tag-create .panel-title {
    margin-top: 0;
}

.btn.danger {
    border-color: var(--danger);
    background: transparent;
    color: var(--danger);
}

.btn.danger:hover:not(:disabled) { border-color: currentColor; }

.combo {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
}

.combo-label {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.combo-input {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--bg);
    color: var(--ink);
    font: inherit;
    font-size: 14px;
}

.combo-input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.combo-list {
    position: absolute;
    z-index: 20;
    top: calc(100% + 4px);
    right: 0;
    left: 0;
    max-height: 230px;
    margin: 0;
    padding: 4px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
    list-style: none;
}

.combo-option {
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
}

.combo-option.aktiv,
.combo-option:hover {
    background: var(--accent-fill);
    color: #fff;
}

.combo-empty {
    padding: 8px 10px;
    color: var(--muted);
    font-size: 13px;
}

/* --- Auswahl und Massenbearbeitung --- */

.tagging-filter {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
}
.tagging-filter-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 180px), 1fr));
    gap: 16px;
    align-items: end;
    min-width: 0;
}
.tagging-filter .field { min-width: 0; grid-template-columns: minmax(0, 1fr); }
.tagging-filter .field input,
.tagging-filter .field select { width: 100%; min-width: 0; max-width: 100%; }
.tagging-filter-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; min-width: 0; }
.tagging-filter-actions .btn { max-width: 100%; text-align: center; }

.panel.selection-editor { padding: 12px 16px; border-radius: 8px; }
.selection-editor-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 12px; margin-bottom: 10px; }
.selection-editor-heading .panel-title { margin: 0; font-size: 16px; }
.selection-editor-heading .selection-note { display: inline; }
.selection-editor-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-left: auto; }
.selection-editor-actions .btn { min-height: 32px; padding: 6px 10px; }
.selection-editor-actions input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.selection-editor-controls { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 12px 24px; }
.selection-editor-add { flex: 0 1 400px; min-width: 0; max-width: 100%; }
.selection-editor-common { flex: 1 1 240px; min-width: 0; }
.selection-editor .tag-form { margin: 0; flex-wrap: nowrap; align-items: flex-end; }
.selection-editor .combo { flex: 0 1 280px; width: 280px; max-width: 100%; }
.selection-editor .combo-label { margin: 0 0 4px; }
.selection-editor .combo-input { height: 32px; padding: 6px 9px; font-size: 13px; }
.selection-editor .tag-form .btn { width: auto; min-height: 32px; padding: 6px 10px; }
.selection-editor .combo-option { overflow-wrap: anywhere; }
.selection-editor .combo-list { z-index: 40; }
.selection-editor .tag-chips { margin: 0; gap: 6px; }
.selection-editor p { margin: 0; }
.selection-editor-common > p { min-height: 32px; display: flex; align-items: center; }

.btn-quiet {
    border: 1px solid var(--line);
    background: transparent;
    color: var(--ink);
}

.btn-quiet:hover {
    border-color: var(--accent);
    background: transparent;
    color: var(--accent-strong);
}

.selection-bar {
    position: sticky;
    z-index: 30;
    top: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    margin-bottom: 18px;
    padding: 14px 18px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.selection-count {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin: 0 auto 0 0;
    color: var(--muted);
    font-size: 13px;
}

.selection-count strong {
    color: var(--accent-strong);
    font-size: 20px;
}

.selection-note {
    display: block;
    color: var(--accent-strong);
    font-size: 12px;
}

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

.selection-all {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.subsection-title {
    margin: 26px 0 12px;
    font-size: 15px;
}

.image-card.pick {
    position: relative;
    /* Haelt Abstand zur klebenden Auswahlleiste, wenn hierher gescrollt wird. */
    scroll-margin-top: 96px;
}

/* Anklickbare Flaeche der Kachel; der Link ins Vollbild liegt daneben. */
.pick-surface {
    display: block;
    cursor: pointer;
}

.image-card.pick .pick-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.image-card.pick img {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    background: var(--surface-soft);
    object-fit: cover;
}

.tagging-gallery .image-meta { grid-template-rows: 18px 16px 16px; }
.tagging-gallery .image-meta strong { line-height: 18px; }
.tagging-gallery .image-meta span { line-height: 16px; }

.pick-box {
    position: absolute;
    z-index: 2;
    top: 10px;
    left: 10px;
    display: grid;
    width: 24px;
    height: 24px;
    place-items: center;
    border: 2px solid rgba(255, 255, 255, 0.9);
    border-radius: 6px;
    background: rgba(23, 32, 31, 0.5);
    color: #fff;
    font-size: 15px;
    font-weight: 800;
    line-height: 1;
}

/* Ausgewaehlt: die Klasse setzt das Skript, :has() wirkt auch ohne JavaScript. */
.image-card.pick.is-selected .pick-box {
    background: var(--accent-fill);
}

.image-card.pick.is-selected .pick-box::after {
    content: "\2713";
}

.image-card.pick:has(.pick-input:checked) .pick-box {
    background: var(--accent-fill);
}

.image-card.pick:has(.pick-input:checked) .pick-box::after {
    content: "\2713";
}

.image-card.pick:has(.pick-input:focus-visible) .pick-box {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.image-card.pick.is-selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(31, 111, 104, 0.35);
}

.image-card.pick:has(.pick-input:checked) {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(31, 111, 104, 0.35);
}

/* Kleiner Link in die Vollbildansicht. */
.pick-open {
    position: absolute;
    z-index: 3;
    top: 10px;
    right: 10px;
    display: grid;
    width: 28px;
    height: 28px;
    place-items: center;
    border: 2px solid rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    background: rgba(23, 32, 31, 0.55);
    color: #fff;
    text-decoration: none;
}

/* Pfeil nach Nordost: Bild gross oeffnen. */
.pick-open::after {
    content: "\2197";
    font-size: 16px;
    font-weight: 700;
    line-height: 1;
}

.pick-open:hover,
.pick-open:focus-visible {
    background: var(--accent-fill);
    outline: none;
}

.pick-tags {
    display: block;
    overflow: hidden;
    color: var(--accent-strong);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pagination button:disabled {
    opacity: 0.45;
    cursor: default;
}

@media (max-width: 760px) {
    .topbar {
        position: static;
        padding: 14px 16px;
    }

    .topbar-user {
        margin-left: 0;
    }

    .import-panel {
        padding: 12px 16px 14px;
    }

    .content {
        padding: 20px 16px 28px;
    }

    .page-header {
        align-items: stretch;
        flex-direction: column;
    }

    .stats {
        text-align: left;
    }

    .tag-galerie {
        grid-template-columns: minmax(0, 1fr);
    }

    .gallery {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
    }

    .pagination {
        flex-wrap: wrap;
    }

    .notice {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar-auth {
        width: 100%;
    }

    .topbar-auth .auth-form {
        width: 100%;
    }

    .topbar-auth .auth-form label {
        flex: 1 1 140px;
    }

    .topbar-auth .auth-form input {
        width: 100%;
    }

    .panel {
        padding: 18px;
    }

    .form-grid {
        align-items: stretch;
        flex-direction: column;
    }

    .form-grid .btn {
        width: 100%;
    }

    .viewer {
        grid-template-columns: minmax(0, 1fr);
    }

    .viewer-stage img {
        max-height: 50vh;
    }

    .tag-form {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .tag-form .btn {
        width: 100%;
    }

    .recht-form {
        align-items: stretch;
        flex-wrap: wrap;
    }

    .recht-form .field {
        flex: 1 1 100%;
    }

    .recht-form .btn {
        width: 100%;
    }

    .selection-bar {
        position: static;
        align-items: stretch;
    }

    .selection-count {
        margin-right: 0;
    }

    .selection-actions {
        flex: 1 1 100%;
        flex-wrap: wrap;
    }

    .selection-actions .btn {
        flex: 1 1 45%;
    }
}

/* Besucherstatistik */
.statistics-filter { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin-bottom: 20px; }
.statistics-summary { display: flex; flex-wrap: wrap; gap: 16px; margin-bottom: 24px; }
.statistics-summary .stats { flex: 1 1 180px; text-align: left; }
.statistics-breakdowns { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 20px; }
.statistics-panel { min-width: 0; margin-bottom: 24px; }
.statistics-panel h2 { font-size: 18px; }
.statistics-panel td:first-child { overflow-wrap: anywhere; }
.statistics-page { display: block; margin-top: 4px; color: var(--muted); overflow-wrap: anywhere; }
.statistics-chart { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(28px, 1fr); gap: 6px; overflow-x: auto; padding-bottom: 8px; }
.statistics-day { display: flex; flex-direction: column; gap: 8px; font-size: 10px; color: var(--muted); text-align: center; }
.statistics-bar-track { height: 130px; display: flex; align-items: flex-end; border-bottom: 1px solid var(--line); }
.statistics-bar { display: block; width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; }
