:root {
    color-scheme: light dark;
    --bg: #ffffff;
    --fg: #1d2127;
    --muted: #5f6873;
    --line: #d8dde3;
    --surface: #f4f6f8;
    --accent: #2457c5;
    --accent-fg: #ffffff;
    --danger: #b3261e;
    --notice: #1e6b34;
    --admin: #6b3fb3;
    --warn: #8a5a00;
    --bar: #2457c5;
    --track: rgb(29 33 39 / 0.07);
    --hover: rgb(29 33 39 / 0.035);
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #16191d;
        --fg: #e4e7eb;
        --muted: #9aa3ad;
        --line: #343a42;
        --surface: #1f2328;
        --accent: #6d9bff;
        --accent-fg: #0b1220;
        --danger: #ff8a80;
        --notice: #7fd29a;
        --admin: #c3a2ff;
        --warn: #f0c060;
        --bar: #6d9bff;
        --track: rgb(228 231 235 / 0.08);
        --hover: rgb(228 231 235 / 0.035);
    }
}

* {
    box-sizing: border-box;
}

/* Wins over the display of buttons and the like. */
[hidden] {
    display: none !important;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--fg);
}

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

header {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    /* Lines up with the content of main, which is centred at 90rem with 1rem of padding. */
    padding: 0.75rem max(1rem, calc((100% - 88rem) / 2));
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

header h1 {
    margin: 0 auto 0 0;
    font-size: 1.1rem;
}

header h1 a {
    color: inherit;
    text-decoration: none;
}

.who {
    color: var(--muted);
    overflow-wrap: anywhere;
}

main {
    max-width: 90rem;
    margin: 0 auto;
    padding: 1rem;
}

h2 {
    font-size: 1.3rem;
    margin: 0.5rem 0;
}

h3 {
    margin: 0;
}

.muted {
    color: var(--muted);
}

.error {
    color: var(--danger);
}

.notice {
    color: var(--notice);
}

/* Buttons, and links that look like them. */
button,
.button {
    display: inline-block;
    padding: 0.4rem 0.9rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--fg);
    font: inherit;
    text-decoration: none;
    cursor: pointer;
}

button:disabled {
    opacity: 0.6;
    cursor: default;
}

.primary {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--accent-fg);
}

.danger {
    border-color: var(--danger);
    color: var(--danger);
}

input,
select {
    font: inherit;
    color: inherit;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
}

input:focus-visible,
select:focus-visible,
summary:focus-visible,
pre:focus-visible,
button:focus-visible,
a:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.toolbar h2 {
    margin-right: auto;
}

.toolbar input {
    flex: 1 1 14rem;
    max-width: 22rem;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    text-align: left;
    padding: 0.45rem 0.5rem;
    border-bottom: 1px solid var(--line);
    overflow-wrap: anywhere;
}

th {
    color: var(--muted);
    font-weight: 600;
}

.badge {
    display: inline-block;
    margin-right: 0.3rem;
    padding: 0.05rem 0.5rem;
    border-radius: 999px;
    background: color-mix(in srgb, currentColor 16%, transparent);
    font-size: 0.78rem;
    font-weight: 500;
    line-height: 1.4;
    vertical-align: middle;
}

.badge.admin {
    color: var(--admin);
}

.badge.disabled {
    color: var(--danger);
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
    max-width: 28rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.check {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

dialog {
    max-width: 30rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--bg);
    color: var(--fg);
}

dialog::backdrop {
    background: rgb(0 0 0 / 0.4);
}

nav {
    display: flex;
    gap: 1.25rem;
}

nav a {
    padding: 0.2rem 0;
    border-bottom: 2px solid transparent;
    color: var(--muted);
    text-decoration: none;
}

nav a:hover {
    color: var(--fg);
}

nav a[aria-current="page"] {
    border-bottom-color: var(--accent);
    color: var(--fg);
    font-weight: 600;
}

.mono,
pre {
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 0.85rem;
}

.nowrap {
    white-space: nowrap;
}

.number {
    text-align: right;
}

.category {
    max-width: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

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

tr.failed td:first-child {
    box-shadow: inset 3px 0 var(--danger);
}

/* Filters, kept in the route's query. */
.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.6rem 0.8rem;
    margin-bottom: 1rem;
}

.filters .field {
    min-width: 9rem;
}

.badge.error,
.badge.severity-error,
.badge.severity-fatal {
    color: var(--danger);
}

.badge.warn,
.badge.severity-warn {
    color: var(--warn);
}

.badge.severity-info {
    color: var(--accent);
}

.badge.severity-debug,
.badge.severity-trace {
    color: var(--muted);
}

/* Facts about one record, as a card of labelled values. */
dl.facts {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 2.5rem;
    margin: 0 0 1.25rem;
    padding: 0.9rem 1.1rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

dl.facts > div {
    min-width: 0;
}

dl.facts dt {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

dl.facts dd {
    margin: 0.15rem 0 0;
    overflow-wrap: anywhere;
}

label.level {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--muted);
}

h2.url {
    overflow-wrap: anywhere;
}

/* The timeline: one row per span, log and call, indented by depth, in the order they started.
   The text takes the width; the lane on the right shows when each row happened in the trace. */
.timeline {
    border-top: 1px solid var(--line);
}

.timeline > details > summary,
.timeline > .record.exchange {
    display: grid;
    grid-template-columns: 5.5rem minmax(0, 1fr) minmax(8rem, 22%);
    align-items: center;
    gap: 1rem;
    padding: 0.45rem 0.75rem;
    border-bottom: 1px solid var(--line);
    cursor: pointer;
    list-style: none;
}

.timeline > details > summary:hover,
.timeline > .record.exchange:hover {
    background: var(--hover);
}

.timeline > details > summary::-webkit-details-marker {
    display: none;
}

.timeline .since,
.timeline .took,
.timeline .meta {
    color: var(--muted);
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 0.8rem;
    white-space: nowrap;
}

.timeline .since {
    text-align: right;
}

.timeline .label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    padding-left: calc(var(--depth, 0) * 1.4rem);
    white-space: nowrap;
}

/* A chevron on the rows that open, and room for one on those that do not, so that names line up. */
.timeline .label::before {
    flex: none;
    width: 0.7rem;
    margin-right: -0.2rem;
    color: var(--muted);
    font-size: 0.7rem;
    content: "";
    transition: transform 0.12s;
}

.timeline summary .label::before {
    content: "▸";
}

.timeline details[open] > summary .label::before {
    transform: rotate(90deg);
}

.timeline .label .badge {
    flex: none;
    margin: 0;
}

.timeline .record.log .label .badge {
    min-width: 3.1rem;
    text-align: center;
}

.timeline .name,
.timeline .body,
.timeline .meta {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Short of room, the status or service gives way before the name or message does. */
.timeline .meta {
    flex: 0 100 auto;
}

.timeline .took {
    flex: none;
}

.timeline .span > summary .name {
    font-weight: 500;
}

.timeline .record.exchange .badge {
    color: var(--muted);
}

.timeline .lane {
    position: relative;
    height: 0.6rem;
    background: var(--track);
    border-radius: 999px;
}

.timeline .bar {
    position: absolute;
    top: 0;
    bottom: 0;
    min-width: 2px;
    border-radius: 999px;
    background: var(--bar);
}

.timeline .bar.call {
    top: 0.1rem;
    bottom: 0.1rem;
    background: var(--muted);
}

.timeline .failed .bar {
    background: var(--danger);
}

.timeline .mark {
    position: absolute;
    top: -0.15rem;
    width: 2px;
    height: 0.9rem;
    margin-left: -1px;
    border-radius: 1px;
    background: var(--muted);
}

.timeline .record.failed .mark {
    background: var(--danger);
}

.timeline .detail {
    padding: 0.6rem 0.75rem 0.85rem calc(var(--depth, 0) * 1.4rem + 7.75rem);
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.timeline .detail .message {
    margin-top: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

table.attributes th,
table.headers th {
    width: 1%;
    white-space: nowrap;
    color: var(--muted);
    font-weight: normal;
}

table.attributes td,
table.headers td {
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    font-size: 0.85rem;
}

.side {
    margin: 1.25rem 0;
}

pre.body {
    max-height: 32rem;
    overflow: auto;
    padding: 0.75rem;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.flag .badge {
    margin-right: 0.4rem;
}

@media (max-width: 40rem) {
    /* The title, the user and Sign out on one row, the sections as tabs across the row under it. */
    header {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr) auto;
        grid-template-areas:
            "title who out"
            "nav nav nav";
        gap: 0 0.75rem;
        padding: 0.5rem 1rem;
    }

    header h1 {
        grid-area: title;
        margin: 0;
    }

    header .who {
        grid-area: who;
        text-align: right;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 0.9rem;
    }

    header > button {
        grid-area: out;
        padding: 0.3rem 0.6rem;
    }

    header nav {
        grid-area: nav;
        gap: 0;
        /* Down to the header's border, so that the current tab's underline sits on it. */
        margin: 0.5rem -1rem -0.5rem;
        border-top: 1px solid var(--line);
        overflow-x: auto;
    }

    header nav a {
        flex: 1;
        padding: 0.65rem 0.5rem;
        text-align: center;
        white-space: nowrap;
        text-decoration: none;
        border-bottom: 2px solid transparent;
    }

    header nav a[aria-current="page"] {
        border-bottom-color: var(--accent);
    }

    /* The time and the text on one row, the lane across the row under them. */
    .timeline > details > summary,
    .timeline > .record.exchange {
        grid-template-columns: 4rem minmax(0, 1fr);
        gap: 0.4rem 0.6rem;
        padding: 0.45rem 0.5rem;
    }

    .timeline .lane {
        grid-column: 2;
    }

    .timeline .label {
        padding-left: calc(var(--depth, 0) * 0.8rem);
    }

    .timeline .detail {
        padding-left: 0.75rem;
    }

    thead {
        display: none;
    }

    /* Columns that say little without their heading, which narrow screens do not show. */
    .wide-only {
        display: none;
    }

    tr {
        display: block;
        padding: 0.4rem 0;
        border-bottom: 1px solid var(--line);
    }

    td {
        display: block;
        padding: 0.1rem 0;
        border: none;
    }
}
