/*
 * TIMUS admin panel — the only stylesheet (spec §9).
 *
 * No framework, no preprocessor, no build step: the panel is server-rendered and has to keep working
 * on a host that only ever serves this one file. Colours come from custom properties so the light and
 * dark schemes below are the only two places a colour is written down.
 *
 * Light is the default and dark is applied by `prefers-color-scheme: dark`. A browser that reports
 * nothing gets light, which is the readable default on an unknown display.
 *
 * Nothing here is an inline style, and no template carries a `style=` attribute: the panel's
 * Content-Security-Policy is `default-src 'self'`, which forbids inline style, and a policy that has
 * to be relaxed for one element is a policy nobody can reason about afterwards.
 */

:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-alt: #fafbfc;
    --border: #d9dde3;
    --border-strong: #b9c0c9;
    --text: #1c2024;
    --muted: #5f6873;
    --accent: #1f5fbf;
    --accent-text: #ffffff;
    --accent-soft: #e7eefa;
    --ok: #17683f;
    --ok-soft: #e2f2e9;
    --warn: #8a5a00;
    --warn-soft: #fdf1dc;
    --danger: #a52121;
    --danger-soft: #fbe7e7;
    --radius: 6px;
    --gap: 16px;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14171a;
        --surface: #1c2024;
        --surface-alt: #22262b;
        --border: #333940;
        --border-strong: #4a525b;
        --text: #e6e9ed;
        --muted: #9aa4af;
        --accent: #6fa8ff;
        --accent-text: #10161f;
        --accent-soft: #1e2b3d;
        --ok: #7ddca6;
        --ok-soft: #16301f;
        --warn: #f0c073;
        --warn-soft: #33280f;
        --danger: #ff8b8b;
        --danger-soft: #3a1c1c;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent); }

h1 { font-size: 20px; margin: 0 0 var(--gap); }
h2 { font-size: 16px; margin: 24px 0 8px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* A form used as a panel inside the grid of actions. */
.grid > form {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 14px;
    background: var(--surface-alt);
}

/* --- chrome ---------------------------------------------------------------------------------- */

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar .brand { font-weight: 600; margin-right: 4px; }
.topbar .who { color: var(--muted); font-size: 13px; }
.topbar .spacer { flex: 1 1 auto; }

.nav { display: flex; flex-wrap: wrap; gap: 4px; }

.nav a {
    padding: 5px 10px;
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    font-size: 14px;
}

.nav a:hover { background: var(--surface-alt); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { padding: var(--gap); max-width: 1200px; margin: 0 auto; }

/* --- surfaces -------------------------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: var(--gap);
    margin-bottom: var(--gap);
}

.card > h2:first-child, .card > h1:first-child { margin-top: 0; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--gap); }

/* One module card on the dashboard. The whole card is the link, so the click target is the card and
   not a word inside it. */
.card-link { display: block; text-decoration: none; color: inherit; }
.card-link .card { margin-bottom: 0; height: 100%; }
.card-link:hover .card { border-color: var(--accent); }
.card .module-id { color: var(--muted); font-family: var(--mono); font-size: 12px; }

.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 24px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: 13px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.empty { color: var(--muted); padding: 12px 0; }

/* --- tables ---------------------------------------------------------------------------------- */

.table-wrap { overflow-x: auto; }

table { border-collapse: collapse; width: 100%; font-size: 14px; }

th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }

th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }

tbody tr:hover { background: var(--surface-alt); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* The audit log's JSON columns: monospaced, wrapped rather than scrolled, and capped in height so one
   long value cannot push every other row off the screen. */
td.json { font-family: var(--mono); font-size: 12px; max-width: 320px; word-break: break-word; }

/* --- badges ---------------------------------------------------------------------------------- */

.badge {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid transparent;
}

.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.neutral { background: var(--surface-alt); color: var(--muted); border-color: var(--border); }

/* --- forms ----------------------------------------------------------------------------------- */

form.inline { display: inline; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }

input[type="text"], input[type="password"], input[type="number"], input[type="search"], select {
    width: 100%;
    padding: 7px 9px;
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
}

input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.field { margin-bottom: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
.row > * { flex: 1 1 160px; }
.row > .shrink { flex: 0 0 auto; }

/* A checkbox with its label beside it: `label { display: block }` above would stack every app on its
   own line, and the assignment form is a set of small toggles rather than a column of fields. */
.checks { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checks label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); margin: 0; }
.checks input { width: auto; }

button, .button {
    display: inline-block;
    padding: 7px 14px;
    font: inherit;
    font-weight: 600;
    color: var(--accent-text);
    background: var(--accent);
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
}

button.secondary, .button.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
button.danger, .button.danger { background: var(--danger); }
button:disabled { opacity: .55; cursor: not-allowed; }

/* --- messages -------------------------------------------------------------------------------- */

.banner { padding: 10px 14px; border-radius: var(--radius); margin-bottom: var(--gap); border: 1px solid transparent; }
.banner.error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.banner.ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.banner.warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }

/* --- pagination ------------------------------------------------------------------------------ */

.pager { display: flex; gap: 10px; align-items: center; margin-top: 12px; font-size: 14px; }

/* --- login / enrolment ----------------------------------------------------------------------- */

.narrow { max-width: 380px; margin: 6vh auto; }
.wide { max-width: 520px; margin: 6vh auto; }

.qr { display: block; margin: 0 auto 12px; background: #fff; padding: 8px; border-radius: var(--radius); width: 208px; height: 208px; }

.setup-secret { font-family: var(--mono); font-size: 14px; word-break: break-all; background: var(--surface-alt); padding: 8px; border-radius: var(--radius); }

/* --- footer ---------------------------------------------------------------------------------- */

.footer { color: var(--muted); font-size: 12px; padding: 0 var(--gap) var(--gap); max-width: 1200px; margin: 0 auto; }

@media (max-width: 640px) {
    main { padding: 12px; }
    .topbar { padding: 8px 12px; }
}
