:root {
    --bg: #0a0e1a;
    --surface: #111729;
    --surface-2: #161e34;
    --border: #222c47;
    --border-strong: #2f3b5c;
    --text: #e7ecf6;
    --muted: #8c97b2;
    --accent: #3b82f6;
    --accent-hover: #2f6fe0;
    --accent-soft: rgba(59, 130, 246, .14);
    --danger: #ef4444;
    --danger-soft: rgba(239, 68, 68, .12);
    --ok: #22c55e;
    --ok-soft: rgba(34, 197, 94, .12);
    --radius: 12px;
    --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --mono: ui-monospace, "Cascadia Code", Consolas, "Liberation Mono", monospace;
    color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 var(--font);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.1rem; display: flex; align-items: center; gap: .5rem; }
code { font-family: var(--mono); font-size: .85em; background: var(--surface-2); border: 1px solid var(--border); padding: .05rem .35rem; border-radius: 6px; }
.icon { flex: none; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.spacer { flex: 1; }
.center-text { text-align: center; }

/* ------------------------------------------------ Topbar */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 1.25rem;
    padding: .75rem max(16px, calc((100vw - 1240px) / 2));
    background: rgba(10, 14, 26, .85);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.brand { display: inline-flex; align-items: center; gap: .6rem; color: var(--text); font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); border: 1px solid rgba(59,130,246,.3); }
.nav { display: flex; gap: .25rem; flex: 1; }
.nav a { display: inline-flex; align-items: center; gap: .45rem; padding: .45rem .75rem; border-radius: 9px; color: var(--muted); font-weight: 500; }
.nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.nav a.active { color: var(--text); background: var(--surface-2); }
.logout { margin: 0; }

/* ------------------------------------------------ Layout */
.container { max-width: 1240px; margin: 0 auto; padding: 1.5rem 16px 4rem; }
.center { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 2rem 16px; gap: 1rem; }
.center-brand { margin-bottom: .5rem; }
.center > .alert { width: 100%; max-width: 420px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.4rem; }
.card.narrow { width: 100%; max-width: 420px; }
.card p { margin: 0 0 1rem; }

.alert { padding: .7rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid; }
.alert.ok { background: var(--ok-soft); border-color: rgba(34,197,94,.35); color: #a7f0c2; }
.alert.err { background: var(--danger-soft); border-color: rgba(239,68,68,.35); color: #fecaca; }
.alert.warn { background: rgba(245,158,11,.1); border-color: rgba(245,158,11,.4); color: #fde68a; font-size: .9rem; }
.alert.warn code { color: var(--text); }

/* ------------------------------------------------ Forms & Buttons */
.form { display: flex; flex-direction: column; gap: .9rem; }
label { display: flex; flex-direction: column; gap: .35rem; font-size: .88rem; font-weight: 600; }
label.check { flex-direction: row; align-items: center; gap: .5rem; font-weight: 500; }
.field-label { margin-top: 1.1rem; }
input, textarea {
    font: inherit; color: var(--text);
    background: var(--bg); border: 1px solid var(--border);
    border-radius: 9px; padding: .62rem .8rem; width: 100%;
    transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input:disabled { color: var(--muted); }
input[type=color] { padding: .2rem; height: 42px; width: 80px; cursor: pointer; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    font: inherit; font-weight: 600; font-size: .9rem; color: var(--text);
    background: var(--surface-2); border: 1px solid var(--border-strong);
    border-radius: 9px; padding: .58rem 1rem; cursor: pointer;
    transition: background .15s, border-color .15s;
    white-space: nowrap;
}
.btn:hover { background: #1c2642; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: #fca5a5; }
.btn.danger:not(.ghost) { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: .4rem .7rem; font-size: .85rem; }
.btn.wide { width: 100%; }
.row { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }

.icon-btn {
    display: inline-grid; place-items: center;
    width: 32px; height: 32px; border-radius: 8px;
    background: transparent; border: 1px solid transparent; color: var(--muted);
    cursor: pointer; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.icon-btn.on { color: var(--accent); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }

/* ------------------------------------------------ Setup */
.checks { list-style: none; padding: .75rem 1rem; margin: 0 0 1rem; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; font-size: .88rem; }
.checks li.ok { color: #a7f0c2; }
.checks li.bad { color: #fca5a5; font-weight: 600; }
.big-code { font-size: 3.5rem; font-weight: 800; color: var(--accent); line-height: 1; margin-bottom: .5rem; }
.lock-icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); margin-bottom: 1rem; }

/* ------------------------------------------------ Dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.2rem; display: flex; flex-direction: column; gap: .2rem; }
.stat-label { color: var(--muted); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: .9rem; color: var(--muted); font-weight: 500; }
.meter { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; margin-top: .4rem; }
.meter span { display: block; height: 100%; background: var(--accent); }

.dropzone {
    position: relative;
    border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
    background: linear-gradient(180deg, var(--surface), var(--bg));
    padding: 2rem 1rem; text-align: center; cursor: pointer;
    transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); outline: none; }
.dropzone.drag { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { display: inline-grid; place-items: center; width: 52px; height: 52px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); margin-bottom: .6rem; }
.dz-title { font-weight: 600; font-size: 1.05rem; }
.dz-sub { color: var(--muted); font-size: .85rem; margin-top: .2rem; }
.uploads { display: flex; flex-direction: column; gap: .5rem; max-width: 560px; margin: 0 auto; max-height: 280px; overflow-y: auto; }
.uploads:not(:empty) { margin-top: 1.2rem; }
.up { text-align: left; background: var(--bg); border: 1px solid var(--border); border-radius: 9px; padding: .55rem .75rem; font-size: .85rem; }
.up-row { display: flex; gap: .75rem; justify-content: space-between; }
.up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-bar { height: 4px; background: var(--surface-2); border-radius: 99px; margin-top: .4rem; overflow: hidden; }
.up-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.up.done .up-bar span { background: var(--ok); }
.up.fail { border-color: rgba(239,68,68,.4); color: #fecaca; }
.up.fail .up-bar span { background: var(--danger); width: 100% !important; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin: 2rem 0 1rem; flex-wrap: wrap; }
.toolbar h1 { margin: 0; font-size: 1.2rem; }
.count { font-weight: 500; font-size: .95rem; margin-left: .25rem; }
.search { position: relative; width: min(320px, 100%); margin: 0; }
.search .icon { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search input { padding-left: 2.2rem; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.file { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; transition: border-color .15s, transform .15s; }
.file:hover { border-color: var(--border-strong); }
.file.new { animation: pop .4s ease; }
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.thumb { position: relative; display: grid; place-items: center; aspect-ratio: 16 / 10; background: var(--bg); overflow: hidden; color: var(--muted); }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-icon { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 16px; background: var(--surface-2); }
.play { position: absolute; right: .5rem; bottom: .5rem; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: rgba(0,0,0,.6); color: #fff; }
.badges { position: absolute; left: .5rem; top: .5rem; display: flex; gap: .3rem; }
.badge { display: inline-flex; align-items: center; gap: .25rem; font-size: .72rem; font-weight: 600; padding: .15rem .45rem; border-radius: 6px; background: rgba(0,0,0,.65); color: #fff; }
.badge.inline { background: var(--accent-soft); color: #bcd4fe; vertical-align: middle; }
.file-body { padding: .7rem .85rem .2rem; min-width: 0; }
.file-name { font-weight: 600; font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { color: var(--muted); font-size: .78rem; }
.nowrap { white-space: nowrap; display: inline-flex; align-items: center; gap: .2rem; }
.file-actions { display: flex; gap: .1rem; padding: .35rem .5rem .55rem; margin-top: auto; }
.file-actions form { margin: 0; }
.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; border: 1px dashed var(--border); border-radius: var(--radius); }
.pager { display: flex; gap: .35rem; justify-content: center; margin-top: 2rem; flex-wrap: wrap; }
.pager a { min-width: 36px; padding: .4rem .6rem; text-align: center; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.pager a.active { background: var(--accent); border-color: var(--accent); }

/* ------------------------------------------------ Ordner & Mehrfachauswahl */
.toolbar-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.toolbar-actions > form:not(.search) { margin: 0; }
.crumbs { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.crumbs a { color: var(--muted); }
.crumbs a:hover { color: var(--text); text-decoration: none; }
.crumbs .icon { color: var(--accent); }
.section-label { color: var(--muted); font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; margin: 1.75rem 0 .75rem; }
.toolbar + .section-label { margin-top: 0; }
.section-label span { margin-left: .3rem; color: var(--text); opacity: .55; }
.folder { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; color: var(--text); transition: border-color .15s; }
.folder:hover { border-color: var(--accent); text-decoration: none; }
.folder-cover { position: relative; display: block; aspect-ratio: 16 / 7; background: linear-gradient(135deg, var(--surface-2), var(--bg)); }
.folder-cover img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: .55; transition: opacity .15s; }
.folder:hover .folder-cover img { opacity: .8; }
.folder-icon { position: absolute; left: .6rem; bottom: .6rem; display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--accent); color: #fff; box-shadow: 0 4px 14px rgba(0,0,0,.4); }
.folder .file-body { padding-bottom: .7rem; }
.folder .file-name, .folder .file-meta { display: block; }
.file { position: relative; }
.pick { position: absolute; top: .55rem; right: .55rem; z-index: 2; width: 20px; height: 20px; margin: 0; padding: 0; cursor: pointer; opacity: 0; transition: opacity .15s; }
.file:hover .pick, .pick:checked, .pick:focus-visible, .selecting .pick { opacity: 1; }
.file:has(.pick:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.bulk {
    position: fixed; left: 50%; bottom: 1rem; z-index: 40; transform: translateX(-50%);
    display: flex; align-items: center; justify-content: center; gap: .45rem; flex-wrap: wrap;
    width: max-content; max-width: calc(100vw - 32px);
    padding: .55rem .6rem .55rem 1rem; background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: 14px;
    box-shadow: 0 14px 40px rgba(0,0,0,.5);
}
.bulk[hidden] { display: none; }
.bulk-count { font-weight: 700; font-size: .9rem; margin-right: .25rem; }
.bulk select { font: inherit; font-size: .85rem; color: var(--text); background: var(--bg); border: 1px solid var(--border-strong); border-radius: 9px; padding: .42rem .6rem; color-scheme: dark; cursor: pointer; }
.selecting .container { padding-bottom: 7rem; }
.selecting .toast { bottom: 6rem; }
@media (hover: none) { .pick { opacity: 1; } }

/* ------------------------------------------------ Datei-Ansicht: nur die Datei, wie die Bildansicht des Browsers */
.layout-view { background: #0e0e0e; }
.media { min-height: 100vh; display: grid; place-items: center; }
.media img, .media video { display: block; max-width: 100vw; max-height: 100vh; }
.media audio { width: min(520px, 90vw); }
.media iframe { width: 100vw; height: 100vh; border: 0; background: #fff; }
.media .code { place-self: stretch; margin: 0; padding: 1.2rem; overflow: auto; font: 13px/1.6 var(--mono); white-space: pre; tab-size: 4; }
.media-file { display: flex; flex-direction: column; align-items: center; gap: .5rem; padding: 2rem; color: var(--text); }
.media-file:hover { text-decoration: none; color: var(--accent); }
.media-file small { color: var(--muted); }

/* ------------------------------------------------ Notizen */
.notes { display: grid; grid-template-columns: 280px 1fr; gap: 1rem; min-height: 70vh; }
.notes-list { display: flex; flex-direction: column; gap: .4rem; }
.notes-list .btn { margin-bottom: .5rem; }
.note-item { display: flex; flex-direction: column; gap: .1rem; padding: .65rem .8rem; border-radius: 10px; color: var(--text); border: 1px solid transparent; min-width: 0; }
.note-item:hover { background: var(--surface); text-decoration: none; }
.note-item.active { background: var(--surface); border-color: var(--border); }
.note-item strong, .note-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .88rem; }
.note-editor { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.note-title { border: 0; border-bottom: 1px solid var(--border); border-radius: 0; background: transparent; font-size: 1.2rem; font-weight: 700; padding: 1rem 1.2rem; }
.note-body { flex: 1; border: 0; border-radius: 0; background: transparent; resize: none; padding: 1rem 1.2rem; min-height: 50vh; font: 14px/1.7 var(--mono); }
.note-title:focus, .note-body:focus { box-shadow: none; }
.note-bar { display: flex; align-items: center; gap: .5rem; padding: .6rem .8rem; border-top: 1px solid var(--border); font-size: .85rem; }

/* ------------------------------------------------ Einstellungen & Admin */
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1rem; margin-bottom: 1rem; align-items: start; }
.settings form { margin: 0; }
.token { display: flex; gap: .3rem; align-items: center; margin: .35rem 0 .6rem; }
.token input { font-family: var(--mono); font-size: .85rem; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
.table td { padding: .6rem; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table .actions { display: flex; gap: .3rem; justify-content: flex-end; }
.table .actions form { margin: 0; }

/* ------------------------------------------------ Toast */
.toast {
    position: fixed; left: 50%; bottom: 1.5rem; z-index: 50;
    transform: translate(-50%, 1rem); opacity: 0; pointer-events: none;
    background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text);
    padding: .65rem 1rem; border-radius: 10px; font-size: .9rem; font-weight: 500;
    box-shadow: 0 10px 30px rgba(0,0,0,.4);
    transition: opacity .2s, transform .2s;
    max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { border-color: rgba(239,68,68,.5); color: #fecaca; }

/* ------------------------------------------------ Mobil */
@media (max-width: 760px) {
    .topbar { gap: .5rem; flex-wrap: wrap; }
    .nav { order: 3; flex: 1 0 100%; overflow-x: auto; }
    .nav a span, .logout span { display: none; }
    .nav a { padding: .45rem .65rem; }
    .layout-app .brand { flex: 1; }
    .notes { grid-template-columns: 1fr; }
    .settings { grid-template-columns: 1fr; }
    .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .75rem; }
    .toolbar-actions { width: 100%; }
    .toolbar-actions .search { flex: 1; }
}
