:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --text: #1d2330;
    --muted: #6b7280;
    --border: #dfe3ea;
    --accent: #2563eb;
    --accent-text: #ffffff;
    --danger: #c0392b;
    --ok-bg: #e8f6ee;
    --ok-text: #1e6b3d;
    --err-bg: #fdecec;
    --err-text: #9b2c2c;
    --warn-bg: #fff6e0;
    --warn-text: #8a5a00;
    --code-bg: #f0f2f5;
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14161b;
        --surface: #1c1f26;
        --text: #e4e7ec;
        --muted: #9097a3;
        --border: #2d323c;
        --accent: #5b8cff;
        --ok-bg: #173324;
        --ok-text: #8fd8ac;
        --err-bg: #3a1c1c;
        --err-text: #f2a3a3;
        --warn-bg: #3a2f14;
        --warn-text: #f0cf80;
        --code-bg: #232731;
    }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a.plain { color: inherit; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 2rem 0 .75rem; }
h1 small, h2 small { color: var(--muted); font-weight: normal; font-size: .9rem; }
code, pre { font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
code { background: var(--code-bg); padding: 0 .3em; border-radius: 4px; }
pre { margin: 0; white-space: pre-wrap; word-break: break-word; }
.muted { color: var(--muted); font-size: .9em; }
.nowrap { white-space: nowrap; }

.top {
    display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.5rem;
    padding: .75rem 1.5rem; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 600; color: var(--text); }
.top nav { display: flex; flex-wrap: wrap; gap: .25rem; flex: 1; }
.top nav a { padding: .3rem .7rem; border-radius: 6px; color: var(--muted); }
.top nav a.active { background: var(--code-bg); color: var(--text); }
.top .user { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .9em; }
main { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

input, select, textarea, button, .button {
    font: inherit; color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: 6px; padding: .4rem .6rem;
}
textarea { width: 100%; resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; }
button, .button { cursor: pointer; display: inline-block; }
button:hover, .button:hover { border-color: var(--accent); text-decoration: none; }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
button.small { padding: .15rem .5rem; font-size: .85em; }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }

.flash { padding: .6rem .9rem; border-radius: 6px; margin-bottom: 1rem; }
.flash.success { background: var(--ok-bg); color: var(--ok-text); }
.flash.error { background: var(--err-bg); color: var(--err-text); }
.flash.warning { background: var(--warn-bg); color: var(--warn-text); }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; }
.card .label { color: var(--muted); font-size: .85em; }
.card .value { font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.card .value.small { font-size: 1rem; word-break: break-all; }
.card .value small { color: var(--muted); font-size: 1rem; font-weight: normal; }

.meta { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0 0 1rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }

.list { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.list th, .list td { text-align: left; vertical-align: top; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
.list th { color: var(--muted); font-weight: 500; font-size: .85em; }
.list tr:last-child td { border-bottom: 0; }
.list tr.disabled td { opacity: .5; }

.heading { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; }
.filters, .row, .actions, .inline { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.row input:not([type]), .row input[name=name] { flex: 1; min-width: 160px; }
.row .narrow { width: 120px; flex: none; }
.filters input[type=search] { flex: 1; min-width: 200px; }
.inline-form { display: inline; }
.check { display: inline-flex; align-items: center; gap: .35rem; }
.stack { display: flex; flex-direction: column; gap: .9rem; margin-bottom: 1.5rem; }
.stack label:not(.check) { display: flex; flex-direction: column; gap: .3rem; color: var(--muted); font-size: .9em; }
.stack label > input, .stack label > select, .stack label > textarea { color: var(--text); font-size: 15px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: .9rem; }
fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 1rem; display: flex; flex-direction: column; gap: .9rem; background: var(--surface); }
legend { padding: 0 .4rem; font-weight: 600; }

.pages { display: flex; flex-wrap: wrap; gap: .3rem; margin: 1rem 0; }
.pages a, .pages span { padding: .2rem .55rem; border-radius: 5px; border: 1px solid var(--border); }
.pages span { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.chunk { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: .75rem; margin-bottom: .75rem; }
.answer { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 8px; padding: 1rem; white-space: pre-wrap; }
details { margin-top: 2rem; }
details pre { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; margin-top: .5rem; }

.login { max-width: 360px; margin: 10vh auto; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 2rem; }

@media (max-width: 640px) {
    main { padding: 1rem; }
    .list { display: block; overflow-x: auto; }
}

.badge { display: inline-block; min-width: 1.4em; padding: 0 .35em; border-radius: 999px; background: var(--danger); color: #fff; font-size: .75em; text-align: center; }
.tabs { display: flex; flex-wrap: wrap; gap: .25rem; margin-bottom: 1rem; }
.tabs a { padding: .3rem .8rem; border-radius: 6px; border: 1px solid var(--border); color: var(--muted); }
.tabs a.active { background: var(--surface); color: var(--text); border-color: var(--accent); }
.spec { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--warn-text); border-radius: 8px; padding: 1rem; margin-bottom: 1rem; }
