/*
    Admin portal.

    Self-contained: no CDN, no webfont, nothing that reaches off the origin.
    Design doc 06 §7 asks for a strict CSP with no CDN references, and the
    cheapest way to keep a CSP strict is to have nothing in the page that wants
    it relaxed.
*/

:root {
    color-scheme: light dark;

    --bg: #f6f6f7;
    --surface: #ffffff;
    --surface-2: #f0f0f2;
    --text: #1b1b1f;
    --muted: #5a5a66;
    --line: #d8d8de;
    --accent: #d43f3a;
    --accent-text: #ffffff;
    --error-bg: #fdecec;
    --error-text: #8f2020;
    --ok-bg: #e8f5ec;
    --ok-text: #1f6b3a;
    --warn-bg: #fdf4e3;
    --warn-text: #8a5a11;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #131316;
        --surface: #1c1c20;
        --surface-2: #232329;
        --text: #ececf1;
        --muted: #a0a0ad;
        --line: #33333c;
        --error-bg: #3a1d1d;
        --error-text: #ffb4b4;
        --ok-bg: #17301f;
        --ok-text: #9fe0b6;
        --warn-bg: #332711;
        --warn-text: #f0cd8a;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 "Segoe UI", system-ui, -apple-system, sans-serif;
}

a { color: var(--accent); }

/* ---------------- the centred card, for the auth pages ---------------- */

body.centred {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.card {
    width: 100%;
    max-width: 440px;
    padding: 32px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
}

.brand {
    margin: 0 0 4px;
    font-size: 20px;
    font-weight: 600;
}

.brand .tag {
    margin-left: 8px;
    padding: 2px 7px;
    border-radius: 5px;
    background: var(--accent);
    color: var(--accent-text);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    vertical-align: 2px;
}

h1 { font-size: 22px; font-weight: 600; margin: 0 0 16px; }
h2 { margin: 0 0 20px; font-size: 17px; font-weight: 600; }

p.lede { color: var(--muted); margin: 0 0 20px; }

button, .button {
    display: inline-block;
    width: 100%;
    padding: 11px;
    border: 0;
    border-radius: 6px;
    background: var(--accent);
    color: var(--accent-text);
    font: inherit;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
}

button.secondary, .button.secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--line);
    font-weight: 500;
    margin-top: 10px;
}

button:hover, .button:hover { filter: brightness(1.08); }

input[type="text"], input[type="email"] {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 16px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
}

input:focus-visible, button:focus-visible, a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.notice {
    padding: 10px 12px;
    margin-bottom: 16px;
    border-radius: 6px;
    font-size: 14px;
}

.notice.error { background: var(--error-bg); color: var(--error-text); }
.notice.ok    { background: var(--ok-bg);    color: var(--ok-text); }
.notice.warn  { background: var(--warn-bg);  color: var(--warn-text); }

.muted { color: var(--muted); font-size: 13px; }

/* Recovery codes, and anything else meant to be read character by character. */
.codes {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin: 16px 0;
    padding: 16px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: 8px;
    font-family: "Cascadia Mono", Consolas, ui-monospace, monospace;
    font-size: 14px;
    letter-spacing: .04em;
}

.keys { list-style: none; margin: 0 0 20px; padding: 0; }

.keys li {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
}

/* ---------------- the portal shell ---------------- */

.shell { display: flex; min-height: 100vh; }

nav.side {
    flex: 0 0 220px;
    padding: 20px 16px;
    background: var(--surface);
    border-right: 1px solid var(--line);
}

nav.side ul { list-style: none; margin: 20px 0 0; padding: 0; }
nav.side li { margin-bottom: 2px; }

nav.side a {
    display: block;
    padding: 8px 10px;
    border-radius: 6px;
    color: var(--text);
    text-decoration: none;
    font-size: 14px;
}

nav.side a:hover  { background: var(--surface-2); }
nav.side a.active { background: var(--accent); color: var(--accent-text); }

main.content { flex: 1; padding: 28px 32px; min-width: 0; }

.who {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    font-size: 13px;
    color: var(--muted);
}

.who .role {
    display: inline-block;
    margin-top: 4px;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--surface-2);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.who form button {
    width: auto;
    margin-top: 10px;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--line);
}

/* ---------------- the data views ---------------- */

section { margin-bottom: 32px; }

section h2 {
    margin: 0 0 12px;
    font-size: 15px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}

section h2 .count {
    margin-left: 6px;
    padding: 1px 7px;
    border-radius: 10px;
    background: var(--surface-2);
    font-size: 12px;
    letter-spacing: 0;
}

.crumb { margin: -8px 0 16px; }

form.search {
    display: flex;
    gap: 8px;
    max-width: 520px;
    margin-bottom: 24px;
}

form.search input { margin: 0; }
form.search button { width: auto; padding: 10px 18px; }

/*
    Wide content scrolls inside its own container. A table of vault GUIDs is
    wider than a narrow window, and a page body that scrolls sideways takes the
    navigation with it.
*/
.table-scroll {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th, td {
    padding: 9px 14px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

th {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    background: var(--surface-2);
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }

td.num, th.num { text-align: right; }

/* A soft-deleted vault or a revoked device: present, and not current. */
tr.dim td { opacity: .55; }

code {
    font-family: "Cascadia Mono", Consolas, ui-monospace, monospace;
    font-size: 13px;
}

.stale { font-size: 12px; font-style: italic; }

dl {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 6px 20px;
    margin: 0;
    font-size: 14px;
}

dt { color: var(--muted); }
dd { margin: 0; }

.pills { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 24px; }

.pill {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 11px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    font-size: 12px;
    white-space: nowrap;
}

.pill.ok   { background: var(--ok-bg);    color: var(--ok-text);    border-color: transparent; }
.pill.warn { background: var(--warn-bg);  color: var(--warn-text);  border-color: transparent; }
.pill.bad  { background: var(--error-bg); color: var(--error-text); border-color: transparent; }

/* ---------------- actions and filters ---------------- */

form.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 24px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

form.filters label,
section.actions label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 12px;
    color: var(--muted);
}

form.filters button { width: auto; padding: 9px 18px; }
form.filters .export { width: auto; padding: 9px 18px; margin: 0; }

select, input[type="date"], input[type="number"] {
    padding: 9px 10px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
    font-size: 14px;
}

section.actions {
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

section.actions .reason {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 340px;
    margin-bottom: 14px;
    font-size: 12px;
    color: var(--muted);
}

section.actions .buttons,
section .reason + .table-scroll { margin-top: 0; }

section.actions .buttons {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px;
}

section.actions .buttons.operator {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
}

section.actions button,
section.actions .button { width: auto; padding: 9px 16px; font-size: 14px; }

section .reason {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 340px;
    margin-bottom: 12px;
    font-size: 12px;
    color: var(--muted);
}

/*
    Destructive actions look destructive. Not a flourish: revoking a device and
    resetting a lockout sit next to each other, and one of them takes something
    away from somebody who is not in the room.
*/
button.danger, .button.danger {
    background: var(--error-bg);
    color: var(--error-text);
    border: 1px solid transparent;
    font-weight: 600;
}

td.row-actions { white-space: nowrap; }
td.row-actions > * + * { margin-left: 6px; }

button.row, .button.row {
    width: auto;
    margin: 0;
    padding: 4px 10px;
    font-size: 12px;
}

button:disabled {
    opacity: .45;
    cursor: not-allowed;
}

.validation-message { color: var(--error-text); font-size: 12px; }

.cannot {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    max-width: 70ch;
}

td.detail { white-space: normal; max-width: 40ch; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------------- the overview ---------------- */

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

.tile {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.tile .figure {
    font-size: 26px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}

.tile .label {
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}

section.alerts { margin-bottom: 28px; }
section.alerts .notice:last-child { margin-bottom: 0; }

ul.todo { max-width: 70ch; padding-left: 20px; }
ul.todo li { margin-bottom: 6px; }

/* ---------------- Blazor's own furniture ---------------- */

#blazor-error-ui {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    padding: 12px 16px;
    background: var(--error-bg);
    color: var(--error-text);
    box-shadow: 0 -1px 2px rgba(0, 0, 0, .2);
}

#blazor-error-ui .dismiss {
    float: right;
    cursor: pointer;
}
