:root {
    /* the seven colours of the WeDo connect logo */
    --green: #BFFF80;
    --sky: #55A3FF;
    --blue: #004E8F;
    --navy: #0B2E63;
    --pink: #FF0A84;
    --red: #F51D00;
    --yellow: #FFE873;

    --paper: #f6f6f8;
    --surface: #ffffff;
    --ink: #111114;
    --muted: #63636b;
    --line: #e4e4e9;
    --accent: var(--blue);
    --accent-ink: #ffffff;
    --accent-soft: #e7f1fb;
    --danger: #c21500;
    --danger-soft: #fdeae7;
    --warn: #7a5600;
    --warn-soft: #fff6cf;
    --radius: 12px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --paper: #101014;
        --surface: #1a1a20;
        --ink: #f1f1f4;
        --muted: #a2a2ad;
        --line: #2e2e37;
        --accent: #7db8ff;
        --accent-ink: #06223d;
        --accent-soft: #16263a;
        --danger: #ff8a7a;
        --danger-soft: #3a1c18;
        --warn: #ffe07a;
        --warn-soft: #332b12;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    background: var(--paper);
    color: var(--ink);
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { margin: 0; font-size: 26px; line-height: 1.2; letter-spacing: -0.01em; text-wrap: balance; }
h2 { margin: 0 0 10px; font-size: 16px; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* layout */
.sidebar {
    position: sticky;
    top: 0;
    flex: 0 0 220px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 22px 14px;
    border-right: 1px solid var(--line);
    background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 8px; margin: 0 6px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand img { flex-shrink: 0; }
.wordmark { display: flex; flex-direction: column; font-size: 15px; line-height: 1.05; letter-spacing: -0.01em; }
.wordmark b { font-size: 19px; font-weight: 800; }
.brand small { align-self: flex-start; margin-left: auto; padding: 2px 7px; border-radius: 999px; background: var(--ink); color: var(--surface); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink); }
.sidebar nav a:hover { background: var(--paper); text-decoration: none; }
.sidebar nav a.active { background: var(--paper); font-weight: 700; }
.nav-label { flex: 1; }
.count { min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--pink); color: #fff; font-size: 12px; font-weight: 700; text-align: center; }
.account { display: flex; flex-direction: column; gap: 8px; padding: 0 8px; font-size: 13px; overflow-wrap: anywhere; }

main { flex: 1; min-width: 0; padding: 32px clamp(16px, 4vw, 48px) 64px; max-width: 1200px; }
body.plain { align-items: center; justify-content: center; background: var(--surface); overflow: hidden; }
/* the brand dot grid, heavily blurred so it reads as soft colour behind the login card */
body.plain::before { content: ""; position: fixed; inset: -120px; z-index: 0; background: url(dots.svg) center / 1320px; filter: blur(30px); opacity: 0.85; }
@media (prefers-color-scheme: dark) { body.plain::before { opacity: 0.5; } }
body.plain main { position: relative; z-index: 1; }
body.plain main { flex: 0 1 380px; padding: 16px; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; }
.page-head p { margin: 6px 0 0; }
.crumb { font-size: 13px; }

/* buttons */
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}
.button:hover { border-color: var(--muted); text-decoration: none; }
.button-primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.button-primary:hover { border-color: var(--accent); filter: brightness(1.08); }
.button-danger { border-color: var(--danger); color: var(--danger); }
.button-ghost { border-color: transparent; background: transparent; }
.button-small { padding: 4px 10px; font-size: 13px; }

/* notices */
.notice { padding: 10px 14px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.notice-error { background: var(--danger-soft); color: var(--danger); }
.empty { padding: 40px 16px; border: 1px dashed var(--line); border-radius: var(--radius); color: var(--muted); text-align: center; }

/* tables */
.search { display: flex; gap: 8px; margin-bottom: 16px; }
.search input { flex: 0 1 320px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; vertical-align: middle; }
th { border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; }
tbody tr + tr td { border-top: 1px solid var(--line); }
tbody tr:hover { background: var(--paper); }
td { font-variant-numeric: tabular-nums; }
td.actions, th.actions { width: 1%; text-align: right; }
.row-title { font-weight: 600; color: var(--ink); }
.pager { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 16px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-ok { border-color: transparent; background: var(--accent-soft); color: var(--accent); }
.badge-warn { border-color: transparent; background: var(--warn-soft); color: var(--warn); }

/* cards and forms */
.card { margin-bottom: 16px; padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.card-danger { border-color: var(--danger-soft); }
.card > :last-child { margin-bottom: 0; }
.links { display: flex; flex-wrap: wrap; gap: 8px; }

.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px 20px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
label { font-size: 13px; font-weight: 600; }
.required { color: var(--danger); }
input, select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper);
    color: var(--ink);
    font: inherit;
}
textarea { resize: vertical; }
.field-invalid input, .field-invalid select, .field-invalid textarea { border-color: var(--danger); }
.hint, .error { margin: 0; font-size: 12.5px; color: var(--muted); }
.error { color: var(--danger); font-weight: 600; }
.preview { font-size: 12.5px; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 16px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; font-size: 14px; }
.check input { width: auto; }
.form-actions { display: flex; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }

.login { display: flex; flex-direction: column; gap: 14px; margin: 0; padding: 32px; border: 0; border-radius: 20px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28); }
.login .brand { margin: 0 0 10px; }
.login .brand img { width: 62px; height: 56px; }
.login .wordmark { font-size: 20px; }
.login .wordmark b { font-size: 26px; }

/* dashboard */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 16px 18px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); }
.stat:hover { border-color: var(--muted); text-decoration: none; }
.stat-value { font-size: 30px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-alert { border-color: var(--pink); }
.columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.columns .card { margin: 0; }
.list { margin: 0; padding: 0; list-style: none; }
.list li { display: flex; flex-direction: column; padding: 8px 0; }
.list li + li { border-top: 1px solid var(--line); }
.list a { font-weight: 600; }
.list span { font-size: 13px; }

/* requests */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 12px; margin-bottom: -1px; border-bottom: 2px solid transparent; color: var(--muted); font-weight: 600; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.active { border-color: var(--accent); color: var(--accent); }
.request-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.request-head h2 { margin: 0; font-size: 18px; }
.request-head p { margin: 2px 0 0; }
.request-actions { display: flex; gap: 8px; flex-shrink: 0; }
.request-text { margin: 14px 0 0; max-width: 70ch; }
.facts { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 14px 0 0; }
.facts dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
.facts dd { margin: 0; }

@media (max-width: 760px) {
    body { flex-direction: column; }
    .sidebar { position: static; flex: none; height: auto; padding: 14px; border-right: 0; border-bottom: 1px solid var(--line); gap: 12px; }
    .sidebar nav { flex-direction: row; flex-wrap: wrap; }
    .account { flex-direction: row; align-items: center; justify-content: space-between; }
    main { padding: 20px 16px 48px; }
    .page-head, .request-head { flex-direction: column; align-items: stretch; }
    .search input { flex: 1; }
}

.add-admin { margin-top: 16px; }
td form { display: inline; }
.narrow { max-width: 420px; display: flex; flex-direction: column; gap: 16px; }
.narrow .form-actions { margin-top: 4px; }

/* brand: every section has one logo colour, shown as a dot in the navigation, on its page title and on its stat */
.dot { flex-shrink: 0; width: 10px; height: 10px; border-radius: 50%; background: var(--section, var(--line)); }
.dot-dashboard, .section-dashboard { --section: var(--ink); }
.dot-requests, .section-requests { --section: var(--pink); }
.dot-costs, .section-costs { --section: var(--yellow); }
.dot-users, .section-users { --section: var(--green); }
.dot-events, .section-events, .dot-sources, .section-sources { --section: var(--sky); }
.dot-offers, .section-offers { --section: var(--yellow); }
.dot-resources, .section-resources { --section: var(--red); }
.dot-topics, .section-topics { --section: var(--blue); }
.dot-admins, .section-admins, .section-password { --section: var(--navy); }
@media (prefers-color-scheme: dark) {
    .dot-topics, .section-topics { --section: #2f7fd0; }
    .dot-admins, .section-admins, .section-password { --section: #3a63b0; }
}
.page-head h1::before { content: ""; display: inline-block; width: 0.5em; height: 0.5em; margin-right: 0.4em; border-radius: 50%; background: var(--section, transparent); vertical-align: 0.08em; }
.stat .dot { width: 22px; height: 22px; margin-bottom: 10px; }
.code { margin: 0 0 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
td .error { font-weight: 400; }
.num { text-align: right; white-space: nowrap; }
.small { font-size: 12.5px; }
table.compact th, table.compact td { padding: 7px 0 7px 14px; }
table.compact th:first-child, table.compact td:first-child { padding-left: 0; }
.columns + .section-title, .section-title { margin: 24px 0 12px; font-size: 18px; }
.columns .card { overflow-x: auto; }
.columns-wide { grid-template-columns: repeat(auto-fit, minmax(460px, 1fr)); }
.nowrap { white-space: nowrap; }
table.compact { table-layout: auto; }
table.compact td:first-child { white-space: normal; overflow-wrap: anywhere; }
