/* ==========================================================================
   Bildarchiv – Oberflaeche
   Dunkles Grundthema, helles Thema automatisch nach Systemeinstellung.
   ========================================================================== */

:root {
    --bg: #0f1115;
    --bg-soft: #161a21;
    --surface: #191e26;
    --surface-2: #1f252f;
    --border: #2a313d;
    --border-strong: #39424f;
    --text: #e8ecf2;
    --text-dim: #9aa4b2;
    --text-faint: #6b7686;
    --accent: #4f8cff;
    --accent-hover: #6b9dff;
    --accent-text: #ffffff;
    --danger: #ef4d5a;
    --danger-soft: rgba(239, 77, 90, .12);
    --success: #35c07f;
    --success-soft: rgba(53, 192, 127, .12);
    --shadow: 0 10px 30px rgba(0, 0, 0, .45);
    --radius: 14px;
    --radius-sm: 9px;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f4f6f9;
        --bg-soft: #ffffff;
        --surface: #ffffff;
        --surface-2: #f0f3f7;
        --border: #e0e5ec;
        --border-strong: #c9d1dc;
        --text: #1a1f27;
        --text-dim: #5c6675;
        --text-faint: #8b95a3;
        --accent: #2f6df5;
        --accent-hover: #1d5ae0;
        --danger: #d92c3c;
        --danger-soft: rgba(217, 44, 60, .09);
        --success: #17925c;
        --success-soft: rgba(23, 146, 92, .1);
        --shadow: 0 10px 30px rgba(20, 30, 50, .12);
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

img { max-width: 100%; display: block; }

/* --------------------------------------------------------------------------
   Buttons und Formularfelder
   -------------------------------------------------------------------------- */

.btn,
.icon-btn,
summary.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 42px;
    padding: 0 15px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-weight: 550;
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background .15s ease, border-color .15s ease, transform .06s ease;
}

.btn:hover, summary.btn:hover { background: var(--border); }
.btn:active, .icon-btn:active { transform: scale(.97); }

.btn:focus-visible,
.icon-btn:focus-visible,
input:focus-visible,
summary:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-text);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-sm { min-height: 34px; padding: 0 10px; font-size: 13px; gap: 5px; }
.btn-block { width: 100%; }

.icon-btn {
    width: 38px;
    min-height: 38px;
    padding: 0;
    border-color: transparent;
    background: transparent;
    color: var(--text-dim);
    border-radius: 50%;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.linklike {
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    color: var(--accent);
    cursor: pointer;
    text-decoration: underline;
}

input[type="text"],
input[type="search"],
input[type="password"] {
    width: 100%;
    min-height: 42px;
    padding: 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg-soft);
    color: var(--text);
    font: inherit;
    font-size: 16px; /* verhindert das Zoomen auf iOS */
}
input::placeholder { color: var(--text-faint); }
input:focus { border-color: var(--accent); outline: none; }

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

/* Das Dateifeld wird per Button bedient; ohne JavaScript blendet es sich ein. */
.file-input { display: none; max-width: 220px; font-size: 13px; }

/* --------------------------------------------------------------------------
   Kopfleiste
   -------------------------------------------------------------------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(160%) blur(12px);
    -webkit-backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--border);
    padding-top: env(safe-area-inset-top);
}

@supports not (background: color-mix(in srgb, red 50%, blue)) {
    .topbar { background: var(--bg); }
}

.topbar-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    color: var(--text);
    font-weight: 680;
    font-size: 16px;
    letter-spacing: -.015em;
}
.brand svg { color: var(--accent); flex: none; }
.brand:hover { color: var(--text); }

.topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-field {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-faint);
    min-height: 40px;
}
.search-field input {
    border: 0;
    background: none;
    min-height: 38px;
    padding: 0;
    width: 150px;
    font-size: 15px;
}
.search-field input:focus { outline: none; }
.search-field:focus-within { border-color: var(--accent); }

/* --------------------------------------------------------------------------
   Grundlayout
   -------------------------------------------------------------------------- */

.wrap {
    max-width: 1280px;
    margin: 0 auto;
    padding: 18px 16px 80px;
}

.breadcrumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    margin-bottom: 14px;
    color: var(--text-faint);
}
.crumb {
    color: var(--text-dim);
    padding: 4px 6px;
    border-radius: 6px;
}
.crumb:hover { background: var(--surface); color: var(--text); }
.crumb.current { color: var(--text); font-weight: 600; }
.breadcrumbs .sep { opacity: .5; }

/* Werkzeugleiste */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
}

.toolbar-info {
    margin-left: auto;
    color: var(--text-faint);
    font-size: 13px;
    white-space: nowrap;
}

/* Meldungen */

.alert {
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 10px;
    font-size: 14px;
    border: 1px solid transparent;
}
.alert-success { background: var(--success-soft); border-color: var(--success); color: var(--success); }
.alert-error { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.alert code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: .92em;
    padding: 1px 5px;
    border-radius: 5px;
    background: rgba(127, 127, 127, .16);
}

/* Ablegezone */

.dropzone {
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius);
    padding: 22px 16px;
    text-align: center;
    color: var(--text-dim);
    margin-bottom: 22px;
    transition: border-color .15s ease, background .15s ease;
}
.dropzone p { margin: 0 0 4px; font-size: 15px; }
.dropzone .hint { font-size: 12.5px; color: var(--text-faint); }
.dropzone.is-over {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, transparent);
    color: var(--text);
}

/* Fortschritt */

.upload-status {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-bottom: 16px;
}
.upload-status-head {
    display: flex;
    justify-content: space-between;
    font-size: 13.5px;
    color: var(--text-dim);
    margin-bottom: 8px;
}
.progress {
    height: 7px;
    border-radius: 999px;
    background: var(--surface-2);
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    width: 0;
    border-radius: 999px;
    background: var(--accent);
    transition: width .2s ease;
}

/* --------------------------------------------------------------------------
   Abschnitte, Ordner, Bilder
   -------------------------------------------------------------------------- */

.section { margin-bottom: 26px; }

.section-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--text-faint);
    margin-bottom: 10px;
    font-weight: 650;
}

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

.folder-card {
    position: relative;
    display: flex;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color .15s ease, background .15s ease;
    min-height: 62px;
}
.folder-card:hover { border-color: var(--border-strong); background: var(--surface-2); }

.folder-link,
a.folder-card {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 12px 12px;
    flex: 1;
    min-width: 0;
    color: var(--text);
}

.folder-icon { color: var(--accent); flex: none; display: flex; }
.folder-up .folder-icon { color: var(--text-faint); }

.folder-body { min-width: 0; display: flex; flex-direction: column; }
.folder-name {
    font-weight: 570;
    font-size: 14.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.folder-meta { font-size: 12px; color: var(--text-faint); }

.folder-card .menu { margin-right: 4px; }

/* Bilder */

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

.card {
    margin: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: border-color .15s ease, transform .12s ease;
}
.card:hover { border-color: var(--border-strong); }

.card-thumb {
    display: block;
    width: 100%;
    aspect-ratio: 1 / 1;
    padding: 0;
    border: 0;
    background: var(--surface-2);
    cursor: zoom-in;
    overflow: hidden;
}
.card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform .25s ease;
}
.card-thumb:hover img { transform: scale(1.04); }

/* Karierter Hintergrund macht Transparenz sichtbar */
.card-thumb {
    background-image:
        linear-gradient(45deg, var(--border) 25%, transparent 25%),
        linear-gradient(-45deg, var(--border) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--border) 75%),
        linear-gradient(-45deg, transparent 75%, var(--border) 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.card-body {
    padding: 9px 10px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.card-name {
    font-size: 13.5px;
    font-weight: 550;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.card-meta { font-size: 11.5px; color: var(--text-faint); }

.card-actions {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 8px;
}
.card-actions .btn-copy { flex: 1; }
.card-actions .menu { margin-left: auto; }

/* Leerer Ordner */

.empty {
    text-align: center;
    padding: 46px 20px;
    color: var(--text-faint);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}
.empty svg { margin: 0 auto 12px; color: var(--border-strong); }
.empty h2 { font-size: 17px; color: var(--text); margin-bottom: 4px; }
.empty p { margin: 0; font-size: 14px; }

.no-results { text-align: center; color: var(--text-faint); padding: 26px 0; }

/* --------------------------------------------------------------------------
   Aufklappmenues (details/summary)
   -------------------------------------------------------------------------- */

.menu, .popover { position: relative; }

.menu > summary,
.popover > summary { list-style: none; }
.menu > summary::-webkit-details-marker,
.popover > summary::-webkit-details-marker { display: none; }

.menu-panel, .popover-panel {
    position: absolute;
    z-index: 30;
    top: calc(100% + 6px);
    left: 0;
    width: 268px;
    max-width: calc(100vw - 32px);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.menu-panel-right { left: auto; right: 0; }

.menu-panel label,
.popover-panel label {
    display: block;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-faint);
    font-weight: 650;
    margin-bottom: 5px;
}

.menu-row { display: flex; gap: 6px; }
.menu-row input { flex: 1; min-width: 0; font-size: 14px; min-height: 36px; }
.menu-form { margin: 0; }
.menu-form + .menu-form { border-top: 1px solid var(--border); padding-top: 10px; }

.popover-panel { width: 300px; }
.popover-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }

/* Auf schmalen Bildschirmen erscheinen Menues als Blatt am unteren Rand */
@media (max-width: 560px) {
    .menu-panel, .popover-panel {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: none;
        border-radius: 18px 18px 0 0;
        padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
        border-width: 1px 0 0;
        animation: sheet-up .18s ease-out;
    }
    @keyframes sheet-up {
        from { transform: translateY(14px); opacity: .6; }
        to { transform: translateY(0); opacity: 1; }
    }
}

/* --------------------------------------------------------------------------
   Bildbetrachter
   -------------------------------------------------------------------------- */

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(8, 10, 14, .94);
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}
.lightbox[hidden] { display: none; }

.lightbox-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
    color: #f1f4f9;
    border-bottom: 1px solid rgba(255, 255, 255, .1);
}
.lightbox-title {
    font-size: 14px;
    font-weight: 550;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.lightbox-tools { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.lightbox-tools .btn { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .16); color: #f1f4f9; }
.lightbox-tools .btn:hover { background: rgba(255, 255, 255, .2); }
.lightbox-tools .icon-btn { color: #f1f4f9; }
.lightbox-tools .icon-btn:hover { background: rgba(255, 255, 255, .14); }

.lightbox-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px;
    min-height: 0;
}
.lightbox-stage img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 6px;
}

/* --------------------------------------------------------------------------
   Kurzmeldung (Toast)
   -------------------------------------------------------------------------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(22px + env(safe-area-inset-bottom));
    transform: translateX(-50%) translateY(12px);
    z-index: 120;
    background: var(--text);
    color: var(--bg);
    padding: 10px 18px;
    border-radius: 999px;
    font-size: 14px;
    font-weight: 550;
    box-shadow: var(--shadow);
    opacity: 0;
    transition: opacity .2s ease, transform .2s ease;
    pointer-events: none;
    max-width: calc(100vw - 32px);
    text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast[hidden] { display: none; }

/* --------------------------------------------------------------------------
   Anmeldeseite
   -------------------------------------------------------------------------- */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 20px;
    background:
        radial-gradient(1000px 500px at 50% -10%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 70%),
        var(--bg);
}

.login-box {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 18px;
    padding: 30px 26px 26px;
    box-shadow: var(--shadow);
    text-align: center;
}
.login-logo {
    width: 60px;
    height: 60px;
    margin: 0 auto 14px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--accent) 15%, transparent);
    color: var(--accent);
}
.login-box h1 { font-size: 21px; margin-bottom: 4px; }
.login-sub { color: var(--text-dim); font-size: 14px; margin: 0 0 20px; }

.login-box form { text-align: left; }
.login-box label {
    display: block;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-faint);
    font-weight: 650;
    margin: 12px 0 5px;
}
.login-box .btn-block { margin-top: 20px; min-height: 46px; }

.password-field { position: relative; }
.password-field input { padding-right: 46px; }
.password-toggle {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 38px;
    height: 38px;
    border: 0;
    background: none;
    color: var(--text-faint);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}
.password-toggle:hover { color: var(--text); }
.password-toggle.is-active { color: var(--accent); }

/* --------------------------------------------------------------------------
   Anpassungen fuer kleine Bildschirme
   -------------------------------------------------------------------------- */

@media (max-width: 720px) {
    .hide-sm { display: none; }
    .search-field input { width: 96px; }
    .toolbar-info { width: 100%; margin-left: 0; order: 3; }
    .wrap { padding: 14px 12px 70px; }
    .image-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
    .folder-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
    .dropzone { padding: 18px 12px; }
}

@media (max-width: 400px) {
    .image-grid { grid-template-columns: repeat(2, 1fr); }
    .folder-grid { grid-template-columns: 1fr; }
    .toolbar .btn { flex: 1; }
}

@media (min-width: 1100px) {
    .image-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
