:root {
    --bg: #f7f7f5;
    --panel: #ffffff;
    --ink: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --accent: #1e3a8a;
    --accent-soft: #eef2ff;
    --warn: #b45309;
    --danger: #b91c1c;
    --pending-bg: #fff7ed;
    --pending-border: #f59e0b;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.7rem 1.25rem;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
}
.topbar .brand a { font-weight: 600; color: var(--ink); }
.topbar nav a { margin-left: 1rem; }
body.admin .topbar { background: #1e293b; color: #f8fafc; }
body.admin .topbar .brand a,
body.admin .topbar nav a { color: #f8fafc; }
body.admin .topbar nav a.muted { color: #cbd5e1; }

.layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 1.25rem;
    max-width: 1200px;
    margin: 1.25rem auto;
    padding: 0 1.25rem;
}
.layout > .sidebar { grid-column: 1; }
.layout > .content { grid-column: 2; }
.layout > .content.centered { grid-column: 1 / -1; max-width: 480px; margin: 4rem auto; }

.sidebar {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    height: fit-content;
}
.sidebar h2 { margin: 0 0 0.6rem; font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.sidebar h3 { margin: 1rem 0 0.4rem; font-size: 0.9rem; }

.content {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.5rem;
}
.content h1 { margin-top: 0; }

.tree { list-style: none; padding-left: 0; margin: 0; }
.tree ul { list-style: none; padding-left: 1rem; margin: 0; border-left: 1px dashed var(--border); }
.tree li { margin: 0.15rem 0; }
.tree a { display: inline-block; padding: 0.15rem 0.35rem; border-radius: 4px; }
.tree a.current { background: var(--accent-soft); font-weight: 600; }
.tree .count { color: var(--muted); font-size: 0.85em; }

.crumbs { color: var(--muted); margin-bottom: 0.6rem; font-size: 0.92rem; }
.crumbs .sep { margin: 0 0.35rem; }

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}
.tile {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.tile.pending {
    background: var(--pending-bg);
    border-color: var(--pending-border);
}
.tile-link {
    display: flex;
    flex-direction: column;
    color: inherit;
}
.tile-link:hover { text-decoration: none; background: rgba(0,0,0,0.02); }
.tile-thumb-wrap {
    aspect-ratio: 3 / 4;
    background: #f3f4f6;
    border-bottom: 1px solid var(--border);
    display: grid;
    place-items: center;
    overflow: hidden;
}
.tile-thumb {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}
.tile-thumb-fallback {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    background: var(--accent);
    color: white;
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: 0.06em;
}
.tile-body {
    padding: 0.75rem 0.85rem;
    min-width: 0;
}
.tile-title { font-weight: 600; word-wrap: break-word; }
.tile-filename { color: var(--muted); font-size: 0.85em; word-wrap: break-word; }
.tile-notes { margin-top: 0.4rem; font-size: 0.9em; }
.tile-meta { margin-top: 0.4rem; color: var(--muted); font-size: 0.8em; }
.status-pending { color: var(--warn); font-weight: 600; }
.status-active { color: #047857; font-weight: 600; }

.tile-actions {
    border-top: 1px solid var(--border);
    padding: 0.6rem 0.85rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}
.tile-actions form { margin: 0; }
.tile-actions details { width: 100%; }
.tile-actions details[open] { padding-top: 0.5rem; }
.tile-actions summary { cursor: pointer; color: var(--accent); }

.node-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-start;
    margin-bottom: 1rem;
}
.node-actions details {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
}
.button-link {
    display: inline-block;
    padding: 0.45rem 0.9rem;
    background: var(--accent);
    color: white !important;
    border-radius: 4px;
}
.button-link:hover { text-decoration: none; opacity: 0.9; }

button, input, textarea, select {
    font: inherit;
}
button {
    background: var(--accent);
    color: white;
    border: 0;
    padding: 0.45rem 0.9rem;
    border-radius: 4px;
    cursor: pointer;
}
button:hover { opacity: 0.9; }
button.danger { background: var(--danger); }

input, textarea, select {
    width: 100%;
    padding: 0.4rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: white;
}
textarea { resize: vertical; }

label {
    display: block;
    margin: 0.5rem 0;
    font-size: 0.9em;
    color: var(--muted);
}

form.stacked label,
form.stacked button { display: block; }
form.stacked button { margin-top: 0.5rem; }

form.inline-form { margin-top: 1rem; }

.login-form { display: flex; flex-direction: column; gap: 0.5rem; }
.login-form h1 { margin: 0; }

.error { color: var(--danger); }
.msg { color: var(--accent); }
.empty { color: var(--muted); font-style: italic; }

.footer {
    text-align: center;
    color: var(--muted);
    padding: 2rem 1rem;
    font-size: 0.85em;
}

@media (max-width: 800px) {
    .layout { grid-template-columns: 1fr; }
    .layout > .sidebar, .layout > .content { grid-column: 1; }
}
