:root {
    --bg: #f6f6f4;
    --panel: #ffffff;
    --sunken: #efefec;
    --text: #1d1d1b;
    --muted: #6b6b66;
    --line: #dededa;
    --accent: #2f5bd3;
    --accent-text: #ffffff;
    --danger: #c0392b;
    --ok: #2e7d4f;
    --radius: 6px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #161615;
        --panel: #1f1f1d;
        --sunken: #2a2a27;
        --text: #ececea;
        --muted: #9b9b95;
        --line: #33332f;
        --accent: #7c9cff;
        --accent-text: #0d0d0c;
        --danger: #ff7a6b;
        --ok: #6fcf97;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 24px 0 8px; }
code, .mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }

.layout { display: grid; grid-template-columns: 230px 1fr; min-height: 100vh; }
nav.side {
    background: var(--panel);
    border-right: 1px solid var(--line);
    padding: 16px 10px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
nav.side .brand { font-weight: 650; padding: 4px 10px 16px; display: flex; gap: 8px; align-items: center; }
nav.side .brand .logo { width: 24px; height: 24px; }
/* The logo is white on transparent, so it sits on a dark tile, which shows in both themes. */
.logo { background: #1d1d1b; border-radius: 5px; padding: 4px; box-sizing: border-box; }
nav.side .group { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; padding: 14px 10px 4px; }
nav.side a { display: block; padding: 6px 10px; border-radius: var(--radius); color: var(--text); }
nav.side a:hover { background: var(--sunken); text-decoration: none; }
nav.side a.active { background: var(--accent); color: var(--accent-text); }
nav.side .me { margin-top: 24px; padding: 10px; border-top: 1px solid var(--line); font-size: 13px; }

main { padding: 24px 32px 64px; min-width: 0; }
.header { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.header .spacer { flex: 1; }
.description { color: var(--muted); margin: -8px 0 16px; max-width: 80ch; }

button, .button {
    font: inherit;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    border-radius: var(--radius);
    padding: 6px 12px;
    cursor: pointer;
}
button:hover { background: var(--sunken); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.small { padding: 2px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }

input, select, textarea {
    font: inherit;
    color: var(--text);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 6px 8px;
    width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
textarea.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; min-height: 200px; }
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: 12px; white-space: nowrap; }
th.sortable { cursor: pointer; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--sunken); }
td { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 0; }

.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px 20px; padding: 20px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.wide { grid-column: 1 / -1; }
.field label { font-weight: 600; font-size: 13px; }
.field .hint { color: var(--muted); font-size: 12px; }
.field .required { color: var(--danger); }
.meta { padding: 0 20px 16px; color: var(--muted); font-size: 12px; display: flex; gap: 16px; flex-wrap: wrap; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--sunken); border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 13px; max-width: 100%; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { border: 0; background: transparent; padding: 0 6px; color: var(--muted); }
.picker { position: relative; }
.picker .options {
    position: absolute; z-index: 10; left: 0; right: 0; top: 100%;
    background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
    max-height: 240px; overflow-y: auto; box-shadow: 0 6px 20px rgba(0,0,0,.15);
}
.picker .options div { padding: 6px 10px; cursor: pointer; }
.picker .options div:hover { background: var(--sunken); }

.media-preview { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.media-preview img, .media-preview video { max-width: 160px; max-height: 100px; border-radius: 4px; background: var(--sunken); }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.media-grid .tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; }
.media-grid .tile .thumb { height: 110px; display: flex; align-items: center; justify-content: center; background: var(--sunken); }
.media-grid .tile img, .media-grid .tile video { max-width: 100%; max-height: 110px; }
.media-grid .tile .caption { padding: 6px 8px; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-grid .tile.selected { outline: 2px solid var(--accent); }

.dialog-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.dialog { background: var(--panel); border-radius: 10px; width: min(900px, 100%); max-height: 90vh; overflow-y: auto; padding: 20px; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth .card { width: min(380px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 12px; }
.auth h1 { display: flex; gap: 10px; align-items: center; }
.auth h1 .logo { width: 30px; height: 30px; padding: 5px; }

.perm-group { margin-bottom: 12px; }
.perm-group .title { font-weight: 600; margin-bottom: 4px; display: flex; gap: 8px; align-items: center; }
.perm-group label { display: inline-flex; gap: 4px; align-items: center; margin: 0 14px 4px 0; font-size: 13px; }

.secret { background: var(--sunken); padding: 10px; border-radius: var(--radius); word-break: break-all; }
.badge { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--sunken); color: var(--muted); }

#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: var(--radius); max-width: 420px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.toast.error { background: var(--danger); color: #fff; }

@media (max-width: 760px) {
    .layout { grid-template-columns: 1fr; }
    nav.side { position: static; height: auto; }
    main { padding: 16px; }
    .form { grid-template-columns: 1fr; padding: 16px; }
}
