:root {
    --bg: #f7f7f8;
    --surface: #ffffff;
    --border: #e0e0e3;
    --text: #1d1d1f;
    --text-muted: #6b6b70;
    --accent: #2b6cb0;
    --accent-contrast: #ffffff;
    --danger: #c0392b;
    --success: #1e7e34;
    --radius: 6px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #17181a;
        --surface: #212226;
        --border: #34353a;
        --text: #f0f0f2;
        --text-muted: #a0a0a6;
        --accent: #5b9bd5;
        --accent-contrast: #0b0c0d;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.4;
}

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

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand { font-weight: 600; font-size: 1.1rem; color: var(--text); }
.topbar-account { display: flex; align-items: center; gap: .5rem; font-size: .9rem; color: var(--text-muted); margin-left: auto; }

.tree-toggle {
    display: none;
    align-items: center;
    gap: .4rem;
    padding: .35rem .7rem;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    border-radius: var(--radius);
}

.layout { display: flex; align-items: flex-start; width: 100%; }

.tree-sidebar {
    flex: 0 0 260px;
    width: 260px;
    box-sizing: border-box;
    padding: 1rem .75rem;
    border-right: 1px solid var(--border);
    background: var(--surface);
    position: sticky;
    top: 0;
    align-self: stretch;
    max-height: 100vh;
    overflow-y: auto;
}

.tree-backdrop { display: none; }

.folder-tree, .folder-tree ul {
    list-style: none;
    margin: 0;
    padding-left: 0;
}
.folder-tree ul { padding-left: 1rem; }

.tree-node { margin: .05rem 0; }

.tree-node > details > summary {
    display: flex;
    align-items: center;
    cursor: pointer;
    list-style: none;
}
.tree-node > details > summary::-webkit-details-marker { display: none; }
.tree-node > details > summary::before {
    content: "\25B8";
    display: inline-block;
    width: 1.1em;
    flex: none;
    color: var(--text-muted);
}
.tree-node > details[open] > summary::before { content: "\25BE"; }
.tree-node:not(:has(> details)) { padding-left: 1.1em; }

.tree-link {
    color: var(--text);
    padding: .2rem .4rem;
    border-radius: var(--radius);
    display: inline-block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tree-link:hover { text-decoration: none; background: var(--bg); }
.tree-link.current { background: var(--accent); color: var(--accent-contrast); }

.sidebar-version {
    margin: 1rem 0 0;
    padding: .2rem .4rem;
    font-size: .75rem;
    color: var(--text-muted);
}

main { flex: 1 1 auto; min-width: 0; width: 100%; padding: 1rem 1.25rem; }
.layout:not(.has-sidebar) main { padding: 1rem; }

.flash { padding: .6rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.flash-success { background: color-mix(in srgb, var(--success) 15%, transparent); color: var(--success); }
.flash-error { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }

.breadcrumbs { margin-bottom: 1rem; font-size: .95rem; color: var(--text-muted); }
.breadcrumbs .sep { margin: 0 .35rem; }

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1rem;
    padding: .75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.toolbar input[type=search],
.toolbar input[type=text],
.toolbar select,
.toolbar input[type=file] {
    padding: .4rem .6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
}

.view-toggle { display: flex; gap: .25rem; }
.view-btn {
    padding: .35rem .7rem;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    border-radius: var(--radius);
    cursor: pointer;
}
.view-btn.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }

.inline-form { display: inline-flex; align-items: center; gap: .4rem; }
.link-button { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }

button { cursor: pointer; }
.bulk-actions > button {
    margin: 0 .5rem .75rem 0;
    padding: .4rem .8rem;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: var(--radius);
}

.entries { display: grid; gap: 1rem; }
.entries.view-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.entries.view-list { grid-template-columns: 1fr; }
.entries.view-rows { grid-template-columns: 1fr; }

.entry {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .5rem;
    display: flex;
    flex-direction: column;
    gap: .3rem;
}

.view-list .entry, .view-rows .entry { flex-direction: row; align-items: center; }

.entry input[type=checkbox] { position: absolute; top: .4rem; left: .4rem; z-index: 2; }

.entry-link { display: flex; flex-direction: column; gap: .3rem; color: var(--text); flex: 1; min-width: 0; }
.view-list .entry-link, .view-rows .entry-link { flex-direction: row; align-items: center; gap: .6rem; }
.entry-link:hover { text-decoration: none; }

.thumb { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: var(--radius); background: var(--bg); }
.view-list .thumb, .view-rows .thumb { width: 48px; height: 48px; aspect-ratio: unset; }

.entry-name { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-size, .comment-count { font-size: .8rem; color: var(--text-muted); }
.entry-description { font-size: .8rem; color: var(--text-muted); margin: 0; }

.icon { display: inline-block; width: 1.4rem; height: 1.4rem; border-radius: 3px; background: var(--border); }
.icon-folder::before { content: "\1F4C1"; }
.icon-file::before { content: "\1F4C4"; }

.pagination { display: flex; gap: .35rem; margin-top: 1rem; }
.pagination a {
    padding: .3rem .65rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
}
.pagination a.active { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }

.login-box {
    max-width: 320px;
    margin: 3rem auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
}
.login-box label { display: block; margin-bottom: .75rem; font-size: .9rem; }
.login-box input { width: 100%; padding: .5rem; margin-top: .25rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--text); }
.login-box button { width: 100%; padding: .55rem; background: var(--accent); color: var(--accent-contrast); border: none; border-radius: var(--radius); }

.image-view { text-align: center; }
.image-view .preview { max-width: 100%; border-radius: var(--radius); }
.back-link { display: inline-block; margin-bottom: 1rem; }

.permalink-row { display: flex; align-items: center; gap: .5rem; max-width: 640px; margin: 1rem auto 0; }
.permalink-row label { color: var(--text-muted); font-size: .85rem; }
.permalink-field { flex: 1; padding: .4rem .6rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; }
.permalink-copy { padding: .4rem .8rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: var(--radius); }

.comments { margin-top: 2rem; max-width: 640px; }
.comment-list { list-style: none; padding: 0; }
.comment-list li { padding: .6rem 0; border-bottom: 1px solid var(--border); }
.comment-list time { color: var(--text-muted); font-size: .8rem; margin-left: .5rem; }
.comment-form textarea { width: 100%; min-height: 5rem; }
.comment-form label { display: block; margin: .5rem 0; }
.comment-form input, .comment-form textarea { width: 100%; padding: .5rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); }

@media (max-width: 860px) {
    .tree-toggle { display: inline-flex; }

    .layout.has-sidebar { display: block; }

    .tree-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 30;
        width: 82%;
        max-width: 320px;
        height: 100vh;
        max-height: none;
        transform: translateX(-100%);
        transition: transform .2s ease-out;
        box-shadow: 2px 0 12px rgba(0, 0, 0, .25);
    }
    .tree-sidebar.open { transform: translateX(0); }

    .tree-backdrop.open {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, .35);
        z-index: 25;
    }

    .layout.has-sidebar main { width: 100%; }
}

@media (max-width: 600px) {
    .topbar { flex-wrap: wrap; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .entries.view-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
}

[hidden] { display: none !important; }
