:root {
    /* Lets the browser draw its own controls (checkboxes, scrollbars, the
       search field) in the matching scheme too. */
    color-scheme: light dark;
    --bg: #f6f7f9;
    --surface: #fff;
    --text: #1d2330;
    --muted: #6b7280;
    --border: #e3e6ea;
    --accent: #2563eb;
    --accent-bg: #e8effd;
    --approve: #15803d;
    --ban: #b91c1c;
    --error-bg: #fdecec;
    --warn: #b45309;
    --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    /* checkbox | registered | last attempt / decided by | MACs | hw_id | device_id | device type | provider | IPs */
    --columns: 40px 9.5rem 10.5rem 11rem 13.5rem 6.5rem minmax(0, 1fr) 11rem minmax(0, 1.1fr);
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14171c;
        --surface: #1c2027;
        --text: #e6e8eb;
        --muted: #9aa2ad;
        --border: #2c323b;
        --accent: #7aa2f7;
        --accent-bg: #243049;
        --error-bg: #3a1f22;
        --warn: #f59e0b;
    }
}

/* `hidden` must win over the display values below (the device table and
   footer are hidden on the Conflicts tab). */
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.4 system-ui, sans-serif;
}

button {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    cursor: pointer;
}
button:disabled { opacity: .4; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.approve { background: var(--approve); border-color: var(--approve); color: #fff; }
button.ban { background: var(--ban); border-color: var(--ban); color: #fff; }

/* Header */
header.top {
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
header.top .brand { display: flex; flex-direction: column; line-height: 1.15; }
header.top h1 { font-size: 18px; margin: 0; white-space: nowrap; }
header.top .version { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
header.top .mode {
    margin-left: -12px;
    padding: 2px 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}
header.top .mode.required { border-color: var(--warn); color: var(--warn); }
header.top nav { display: flex; gap: 4px; }
header.top nav a {
    padding: 6px 12px;
    border-radius: 6px;
    color: var(--muted);
    text-decoration: none;
    white-space: nowrap;
}
header.top nav a.active { background: var(--accent-bg); color: var(--accent); }
header.top .count { margin-left: 2px; font-variant-numeric: tabular-nums; opacity: .8; }
header.top nav a.attention .count { color: var(--warn); font-weight: 600; opacity: 1; }
header.top input {
    flex: 1;
    max-width: 360px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
}
header.top .matched {
    margin-left: -16px;
    color: var(--muted);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
header.top .header-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
header.top .updated { color: var(--muted); font-size: 13px; white-space: nowrap; margin-right: 4px; }
header.top .updated.stale { color: var(--warn); }
header.top .live { color: var(--approve); font-size: 13px; white-space: nowrap; margin-right: 4px; }
header.top .live::before {
    content: "";
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 6px;
    border-radius: 50%;
    background: currentColor;
    vertical-align: 1px;
}

.page { max-width: 1680px; margin: 0 auto; padding: 16px 24px 72px; }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
.error {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: var(--error-bg);
    color: var(--ban);
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 12px;
}
.empty { color: var(--muted); text-align: center; padding: 24px; }

/* Device table. Rows are grid rows rather than table rows: internal table
   boxes can't take containment, and content-visibility needs it. With it the
   browser skips style/layout/paint for rows outside the viewport, while they
   stay in the DOM (select-all, Ctrl+F and scrolling keep working). */
table.devices {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
}
.devices thead, .devices tbody { display: block; }
.devices tr { display: grid; grid-template-columns: var(--columns); }
.devices tr[hidden] { display: none; }
.devices tbody tr {
    content-visibility: auto;
    contain-intrinsic-size: auto 31px;
}
.devices tbody tr:hover { background: var(--bg); }
/* Devices that arrived through the live feed fade in from the accent colour. */
.devices tbody tr.fresh { animation: fresh 6s ease-out; }
@keyframes fresh { from { background: var(--accent-bg); } to { background: transparent; } }
.devices thead {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--surface);
}
.devices th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .03em;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}
.devices th button.sort {
    all: unset;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
}
.devices th button.sort:hover, .devices th:not([aria-sort="none"]) button.sort { color: var(--text); }
.devices th button.sort:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.devices th .arrow { font-size: 10px; }
.devices td {
    padding: 6px 12px;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    text-overflow: ellipsis;
}
.devices th:first-child, .devices td:first-child { padding-right: 0; text-overflow: clip; }
.devices .mono { font-family: var(--mono); font-size: 13px; }
.devices .macs { white-space: pre-line; }
.devices .type { white-space: nowrap; }
.devices .registered, .devices .activity { white-space: nowrap; font-variant-numeric: tabular-nums; }
.devices .carrier { color: var(--muted); font-size: 13px; }
.devices tbody tr { cursor: pointer; }
.devices .provider { white-space: nowrap; }
.devices .provider .sub { color: var(--muted); font-size: 13px; }
.devices .provider.warn .sub { color: var(--warn); }
.devices .provider .failed { margin-left: 6px; color: var(--warn); font-size: 13px; font-weight: 600; }

/* Conflicts: few rows, a plain table. */
section.conflicts .intro { margin: 0 0 12px; color: var(--muted); max-width: 72rem; }
table.conflicts {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
}
.conflicts th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .03em;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}
.conflicts td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.conflicts .mono { font-family: var(--mono); font-size: 13px; }
.conflicts .when { white-space: nowrap; font-variant-numeric: tabular-nums; }
.conflicts .sub { color: var(--muted); font-size: 12px; font-family: system-ui, sans-serif; }
.conflicts .taken { color: var(--warn); }
.conflicts .problem p { margin: 0 0 4px; }
.conflicts .problem p:last-child { margin-bottom: 0; }
.conflicts td.actions { white-space: nowrap; text-align: right; }
.conflicts td.actions button + button { margin-left: 8px; }

/* Detail panel: over the page's right edge. */
aside.detail {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    width: min(480px, 100vw);
    overflow-y: auto;
    background: var(--surface);
    border-left: 1px solid var(--border);
    box-shadow: -8px 0 24px rgb(0 0 0 / .12);
    padding: 0 20px 24px;
}
aside.detail header {
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 0 10px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
aside.detail h2 { margin: 0; font-size: 15px; overflow-wrap: anywhere; }
aside.detail button.close { padding: 2px 10px; font-size: 18px; line-height: 1; }
aside.detail h3, .stats h3 {
    margin: 18px 0 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .03em;
}
aside.detail dl { display: grid; grid-template-columns: 9rem 1fr; gap: 6px 12px; margin: 0; }
aside.detail dt { color: var(--muted); }
aside.detail dd { margin: 0; overflow-wrap: anywhere; }
aside.detail .macs { white-space: pre-line; }
aside.detail p { margin: 0; }
.mono { font-family: var(--mono); font-size: 13px; }
.sub { color: var(--muted); font-size: 12px; }
.detail-text { overflow-wrap: anywhere; }

/* Plain tables (statistics, detail panel): few rows. */
table.plain { width: 100%; border-collapse: collapse; }
.plain th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
}
.plain td { padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.plain .num { text-align: right; font-variant-numeric: tabular-nums; }
.plain .when { white-space: nowrap; font-variant-numeric: tabular-nums; }
/* A status mark: icon in the warning colour beside text in normal ink. */
.flag { color: var(--warn); font-weight: 600; }
button.link {
    all: unset;
    cursor: pointer;
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}
button.link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Statistics */
section.stats .tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(13rem, 1fr));
    gap: 12px;
}
section.stats .tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
}
section.stats .tile .label { color: var(--muted); font-size: 13px; }
section.stats .tile .value { font-size: 28px; font-weight: 600; margin: 2px 0; }
section.stats .stats-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(28rem, 1fr));
    gap: 16px;
}
section.stats .panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0 14px 10px;
    margin-top: 16px;
    min-width: 0;
}
section.stats .note { color: var(--muted); font-size: 12px; margin-top: 12px; }

footer.actions {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 24px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}
footer.actions .selection { margin-right: auto; color: var(--muted); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card {
    width: 100%;
    max-width: 360px;
    padding: 32px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    text-align: center;
}
.login h1 { margin: 0 0 8px; font-size: 22px; }
.login p { margin: 0 0 24px; color: var(--muted); }
.login button { width: 100%; padding: 10px; }
