:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --text: #1d2330;
    --muted: #5d6677;
    --border: #dde1e7;
    --accent: #2563eb;
    --accent-text: #ffffff;
    --danger: #c42b2b;
    --ok-bg: #e7f6ec;
    --ok-text: #17663a;
    --err-bg: #fdecec;
    --err-text: #9b1c1c;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
    font-size: 15px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111418;
        --surface: #1a1e24;
        --surface-2: #232830;
        --text: #e6e9ee;
        --muted: #9aa3b2;
        --border: #2e3440;
        --accent: #4f8cff;
        --danger: #ff6b6b;
        --ok-bg: #12301f;
        --ok-text: #7ee2a8;
        --err-bg: #3a1717;
        --err-text: #ffaaaa;
        --shadow: none;
    }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100vh; display: flex; flex-direction: column; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
p { margin: .25rem 0 .75rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: .9em; }
code { background: var(--surface-2); padding: .1rem .35rem; border-radius: 5px; word-break: break-all; }

.topbar { display: flex; align-items: center; gap: 1.5rem; padding: .6rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .5rem; color: var(--text); font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand b { color: var(--accent); }
.mainnav { display: flex; gap: .25rem; flex: 1; flex-wrap: wrap; }
.mainnav a, .usermenu a { color: var(--muted); padding: .35rem .7rem; border-radius: 7px; }
.mainnav a:hover, .usermenu a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.mainnav a.active, .usermenu a.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.usermenu { display: flex; align-items: center; gap: .5rem; }
.usermenu form { margin: 0; }

.container { width: 100%; max-width: 1080px; margin: 0 auto; padding: 1.75rem 1.25rem 3rem; flex: 1; }
.narrow { max-width: 440px; margin: 3rem auto; }
.footer { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: .4rem 1rem; color: var(--muted); font-size: .8rem; padding: 1rem; }
.footer-link { display: inline-flex; align-items: center; gap: .35rem; color: var(--muted); }
.footer-link:hover { color: var(--text); text-decoration: none; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head p { color: var(--muted); margin: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem 1.4rem; margin-bottom: 1.25rem; }
.card > h2:first-child { margin-top: 0; }
.grid { display: grid; gap: 1.25rem; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: none; }
td.actions { text-align: right; white-space: nowrap; }
td.actions form { display: inline; }

.swatch { display: inline-block; width: .8rem; height: .8rem; border-radius: 50%; vertical-align: middle; margin-right: .45rem; border: 1px solid rgba(0,0,0,.15); }
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin-right: .25rem; }
.badge.accent { background: color-mix(in srgb, var(--accent) 15%, transparent); color: var(--accent); }

form.stack { display: flex; flex-direction: column; gap: .9rem; }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field label, .label { font-weight: 600; font-size: .88rem; }
.field .hint { color: var(--muted); font-size: .8rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1; min-width: 160px; }
input[type=text], input[type=password], input[type=email], input[type=url], input[type=number], select, textarea {
    font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .5rem .65rem; width: 100%;
}
input[type=color] { width: 3rem; height: 2.3rem; padding: .15rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 0; border-color: var(--accent); }
.check { display: flex; align-items: center; gap: .5rem; font-weight: normal; }
.checks { display: flex; gap: 1.25rem; flex-wrap: wrap; }

.btn, button { font: inherit; cursor: pointer; border-radius: 8px; padding: .5rem 1rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); display: inline-flex; align-items: center; gap: .4rem; }
.btn:hover, button:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover, button.primary:hover { filter: brightness(1.08); }
.btn.danger, button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn.small, button.small { padding: .25rem .6rem; font-size: .85rem; }
button.link { background: none; border: none; color: var(--muted); padding: .35rem .5rem; }
button.link:hover { color: var(--text); }
.btn.block, button.block { width: 100%; justify-content: center; }

.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; }
.alert.ok { background: var(--ok-bg); color: var(--ok-text); }
.alert.err { background: var(--err-bg); color: var(--err-text); }
.secret { font-family: ui-monospace, Consolas, monospace; font-size: 1.15rem; letter-spacing: .05em; background: var(--surface-2); padding: .6rem .9rem; border-radius: 8px; display: inline-block; user-select: all; }

.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .8rem; margin: 1rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
details summary { cursor: pointer; font-weight: 600; }
.empty { color: var(--muted); padding: 1rem 0; }

@media (max-width: 640px) {
    .topbar { padding: .6rem 1rem; gap: .75rem; }
    .container { padding: 1.25rem .9rem 2rem; }
    th:nth-child(n+3), td:nth-child(n+3):not(.actions) { display: none; }
}
pre { background: var(--surface-2); padding: .75rem 1rem; border-radius: 8px; overflow-x: auto; }
fieldset { border: 1px solid var(--border); }
