:root {
    --bg: #f4f3f0;
    --panel: #ffffff;
    --line: #e2e0da;
    --text: #1f1e1c;
    --muted: #6f6b63;
    --accent: #2f6b4f;
    --accent-soft: #e3efe8;
    --danger: #b3261e;
    --sel: #2f6b4f;
    --radius: 8px;
    --tile: 200px;
    --shadow: 0 6px 24px rgba(0, 0, 0, .12);
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #171716;
        --panel: #22211f;
        --line: #36342f;
        --text: #ecebe7;
        --muted: #a29e95;
        --accent: #6fbf93;
        --accent-soft: #24382d;
        --danger: #ef6a60;
        --sel: #6fbf93;
        --shadow: 0 6px 24px rgba(0, 0, 0, .5);
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
    font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
code { font-size: .9em; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
kbd {
    font: 12px ui-monospace, monospace; border: 1px solid var(--line); border-bottom-width: 2px;
    border-radius: 4px; padding: 0 5px; background: var(--panel);
}

/* ---------- Buttons & Formulare */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    font: inherit; color: var(--text); text-decoration: none; cursor: pointer;
    background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
    padding: 6px 12px; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 1px;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary { color: #0d1a13; } }
.btn-danger { color: var(--danger); }
.btn-small { padding: 3px 9px; font-size: 13px; }
.btn-icon { width: 32px; justify-content: center; padding: 6px 0; }
input[type=text], input[type=password], input[type=search], select, textarea {
    font: inherit; color: var(--text); background: var(--panel);
    border: 1px solid var(--line); border-radius: 6px; padding: 6px 9px; width: 100%;
}
textarea { resize: vertical; }
label { display: block; margin: 12px 0 4px; font-weight: 500; }
label > input, label > textarea, label > select, label > div { margin-top: 4px; font-weight: 400; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
.form-error { color: var(--danger); display: block; }

/* ---------- Einfache Seiten (Login, Übersicht) */
.page-simple { display: grid; place-items: center; min-height: 100%; padding: 24px; }
.simple-card {
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
    padding: 28px 32px; width: min(380px, 100%); box-shadow: var(--shadow);
}
.simple-card.wide { width: min(640px, 100%); }
.simple-card form .btn { margin-top: 16px; width: 100%; justify-content: center; }
.project-list { list-style: none; padding: 0; margin: 20px 0 0; display: grid; gap: 8px; }
.project-list a {
    display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; text-decoration: none; color: var(--text);
    border: 1px solid var(--line); border-radius: 8px;
}
.project-list a:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- App-Layout */
.app {
    display: grid; height: 100vh;
    grid-template-columns: 280px 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas: "top top" "side main";
}
.topbar {
    grid-area: top; display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand h1 { font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { text-decoration: none; font-size: 18px; color: var(--muted); }
.save-state { font-size: 12px; color: var(--muted); }
.save-state.err { color: var(--danger); }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar input[type=search] { width: 200px; }
.toolbar select { width: auto; max-width: 220px; }
.size-ctl { display: flex; align-items: center; gap: 6px; margin: 0; color: var(--muted); }
.size-ctl input { width: 90px; margin: 0; }

.menu-wrap { position: relative; }
.menu {
    position: absolute; right: 0; top: calc(100% + 4px); z-index: 30; min-width: 260px;
    background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow);
    padding: 4px; display: flex; flex-direction: column;
}
.menu[hidden] { display: none; }
.menu a, .menu button {
    text-align: left; padding: 7px 10px; border-radius: 5px; cursor: pointer; color: var(--text);
    text-decoration: none; background: none; border: 0; font: inherit; display: flex; align-items: center; gap: 8px;
}
.menu a:hover, .menu button:hover { background: var(--accent-soft); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; width: 100%; }

/* ---------- Seitenleiste */
.sidebar {
    grid-area: side; background: var(--panel); border-right: 1px solid var(--line);
    overflow-y: auto; display: flex; flex-direction: column; padding: 12px 10px;
}
.views { display: flex; flex-direction: column; gap: 1px; margin-bottom: 14px; }
.view-item, .type-item {
    display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 6px;
    cursor: pointer; user-select: none; border: 1px solid transparent; position: relative;
}
.view-item:hover, .type-item:hover { background: var(--bg); }
.view-item.active, .type-item.active { background: var(--accent-soft); }
.view-item .count, .type-item .count { margin-left: auto; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 8px 6px; }
.sidebar-head h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.type-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.type-item .dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.type-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.type-item .key {
    font: 11px ui-monospace, monospace; color: var(--muted); width: 14px; text-align: center; flex: none;
}
.type-item .acts { display: none; gap: 2px; margin-left: auto; }
.type-item:hover .acts, .type-item:focus-within .acts { display: flex; }
.type-item:hover .count, .type-item:focus-within .count { display: none; }
.type-item .acts button {
    border: 0; background: none; cursor: pointer; color: var(--muted); width: 24px; height: 22px;
    border-radius: 4px; font-size: 14px; padding: 0;
}
.type-item .acts button:hover { background: var(--line); color: var(--text); }
.has-selection .type-item .add-sel { display: inline-block; }
.type-item.drop { border-color: var(--accent); background: var(--accent-soft); }
.type-item.dragging { opacity: .4; }
.type-item.drop-before::before, .type-item.drop-after::after {
    content: ""; position: absolute; left: 6px; right: 6px; height: 2px; background: var(--accent);
}
.type-item.drop-before::before { top: -1px; }
.type-item.drop-after::after { bottom: -1px; }
.sidebar-foot { margin-top: auto; padding: 16px 8px 4px; font-size: 13px; }
.sidebar-foot p { margin: 0 0 8px; }

/* ---------- Hauptbereich */
.main { grid-area: main; overflow-y: auto; padding: 0 16px 40px; position: relative; }
.selbar {
    position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    background: var(--accent); color: #fff; padding: 8px 12px; border-radius: 0 0 8px 8px; margin: 0 -4px;
    box-shadow: var(--shadow);
}
@media (prefers-color-scheme: dark) { .selbar { color: #0d1a13; } }
.selbar[hidden] { display: none; }
.selbar #selCount { font-weight: 600; }
.selbar-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.selbar .btn { background: rgba(255, 255, 255, .15); border-color: rgba(255, 255, 255, .35); color: inherit; }
.selbar .btn:hover { background: rgba(255, 255, 255, .28); }
.selbar .menu .btn, .selbar .menu a, .selbar .menu button { color: var(--text); }

.view-info { padding: 14px 4px 10px; display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.view-info h2 { font-size: 18px; }
.view-info .desc { color: var(--muted); white-space: pre-line; flex-basis: 100%; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(var(--tile), 1fr)); gap: 12px; outline: none; }
.folder-head {
    grid-column: 1 / -1; margin: 10px 0 -2px; font-size: 12px; font-weight: 600;
    color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
}
.empty { color: var(--muted); text-align: center; padding: 60px 20px; }

.card {
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    overflow: hidden; cursor: pointer; user-select: none; position: relative;
    transition: box-shadow .12s, transform .12s;
}
.card:hover { box-shadow: var(--shadow); }
.card.selected { outline: 3px solid var(--sel); outline-offset: -1px; }
.card.discarded .thumb img { opacity: .35; filter: grayscale(1); }
.card.drag-ghost { opacity: .35; }
.card.drop-before { box-shadow: -5px 0 0 -1px var(--accent); }
.card.drop-after { box-shadow: 5px 0 0 -1px var(--accent); }
.thumb { aspect-ratio: 3 / 2; background: var(--bg); display: grid; place-items: center; overflow: hidden; }
.thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.card .check {
    position: absolute; top: 6px; left: 6px; width: 22px; height: 22px; border-radius: 50%;
    border: 2px solid #fff; background: rgba(0, 0, 0, .25); display: grid; place-items: center;
    color: #fff; font-size: 13px; opacity: 0; transition: opacity .1s;
}
.card:hover .check, .card.selected .check { opacity: 1; }
.card.selected .check { background: var(--sel); border-color: var(--sel); }
.card .pos {
    position: absolute; top: 6px; right: 6px; min-width: 24px; height: 24px; padding: 0 6px;
    border-radius: 12px; background: rgba(0, 0, 0, .65); color: #fff; font-size: 12px; font-weight: 600;
    display: grid; place-items: center;
}
.card .flag {
    position: absolute; top: 6px; right: 6px; background: rgba(0, 0, 0, .65); color: #fff;
    font-size: 11px; padding: 2px 7px; border-radius: 10px;
}
.card .pos + .flag { top: 36px; }
.card .meta { padding: 6px 8px 8px; }
.card .fname { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .dims { font-size: 11px; color: var(--muted); display: flex; gap: 6px; }
.card .dims .note { margin-left: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 5px; min-height: 4px; }
.chip {
    font-size: 11px; line-height: 1; padding: 3px 4px 3px 7px; border-radius: 10px; color: #fff;
    display: inline-flex; align-items: center; gap: 2px; max-width: 100%;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button {
    border: 0; background: none; color: inherit; cursor: pointer; padding: 0 2px; font-size: 13px; line-height: 1;
    opacity: .7;
}
.chip button:hover { opacity: 1; }

/* ---------- Dialoge */
dialog { border: 0; padding: 0; color: var(--text); background: var(--panel); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.modal { border-radius: 12px; width: min(460px, calc(100% - 32px)); box-shadow: var(--shadow); }
.modal form { padding: 22px 24px; }
.modal h2 { font-size: 17px; margin-bottom: 4px; }
.modal-actions { display: flex; gap: 8px; margin-top: 20px; align-items: center; }
.spacer { flex: 1; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatches button {
    width: 26px; height: 26px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0;
}
.swatches button.on { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--panel); }
.help { padding-left: 20px; margin: 12px 0; }
.help li { margin-bottom: 6px; }
.keys { border-collapse: collapse; width: 100%; font-size: 13px; }
.keys td { padding: 4px 6px; border-top: 1px solid var(--line); }
.keys td:first-child { white-space: nowrap; }

.lightbox {
    width: 100vw; height: 100vh; max-width: none; max-height: none; margin: 0;
    background: #0e0e0d; display: none; grid-template-columns: 1fr 320px;
}
.lightbox[open] { display: grid; }
.lb-stage { position: relative; display: grid; place-items: center; overflow: hidden; padding: 16px; }
.lb-stage img { max-width: 100%; max-height: calc(100vh - 32px); object-fit: contain; }
.lb-nav {
    position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 80px; border: 0;
    background: rgba(255, 255, 255, .08); color: #fff; font-size: 40px; cursor: pointer; border-radius: 8px;
}
.lb-nav:hover { background: rgba(255, 255, 255, .18); }
.lb-prev { left: 12px; }
.lb-next { right: 12px; }
.lb-panel { background: var(--panel); padding: 20px; overflow-y: auto; position: relative; }
.lb-panel h2 { font-size: 15px; word-break: break-all; padding-right: 30px; }
.lb-panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 6px; }
.lb-panel .btn { margin-top: 14px; }
.lb-close {
    position: absolute; top: 12px; right: 12px; border: 0; background: none; font-size: 26px;
    cursor: pointer; color: var(--muted); line-height: 1;
}
.lb-types { display: flex; flex-direction: column; gap: 2px; }
.lb-types label { margin: 0; display: flex; align-items: center; gap: 8px; font-weight: 400; padding: 3px 0; cursor: pointer; }
.lb-types .dot { width: 10px; height: 10px; border-radius: 50%; }
.lb-types .key { margin-left: auto; font: 11px ui-monospace, monospace; color: var(--muted); }

.toast {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100;
    background: var(--text); color: var(--panel); padding: 9px 16px; border-radius: 8px; box-shadow: var(--shadow);
    display: flex; gap: 12px; align-items: center;
}
.toast[hidden] { display: none; }
.toast button { background: none; border: 0; color: inherit; font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; }

@media (max-width: 760px) {
    .app { grid-template-columns: 1fr; grid-template-rows: auto auto 1fr; grid-template-areas: "top" "side" "main"; }
    .sidebar { max-height: 38vh; border-right: 0; border-bottom: 1px solid var(--line); }
    .lightbox { grid-template-columns: 1fr; grid-template-rows: 55vh auto; }
    .lb-stage img { max-height: 52vh; }
}
