:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --panel: #ffffff;
    --ink: #18202a;
    --muted: #687586;
    --line: #dde3ea;
    --accent: #0d6b68;
    --accent-2: #bb5a21;
    --good: #11763f;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 14px/1.45 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    -webkit-text-size-adjust: 100%;
}

.topbar {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 24px;
    padding: 24px 28px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}

.topbar > div {
    min-width: 220px;
}

h1,
h2,
h3 {
    margin: 0;
    letter-spacing: 0;
}

h1 {
    font-size: 24px;
}

h2 {
    margin-bottom: 12px;
    font-size: 17px;
}

h3 {
    margin: 18px 0 10px;
    font-size: 14px;
}

p {
    margin: 4px 0 0;
    color: var(--muted);
}

.filters {
    display: flex;
    align-items: end;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.filter-panel {
    min-width: min(760px, 100%);
}

.filter-panel summary {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    color: var(--accent);
    cursor: pointer;
    font-weight: 700;
    list-style: none;
    user-select: none;
}

.filter-panel summary::-webkit-details-marker {
    display: none;
}

.filter-panel summary::before {
    content: "▸";
    transition: transform 150ms ease;
}

.filter-hide-label {
    display: none;
}

.filter-panel[open] summary {
    margin-bottom: 10px;
}

.filter-panel[open] summary::before {
    transform: rotate(90deg);
}

.filter-panel[open] .filter-show-label {
    display: none;
}

.filter-panel[open] .filter-hide-label {
    display: inline;
}

label {
    display: grid;
    gap: 4px;
    color: var(--muted);
    font-size: 12px;
}

.filters label {
    min-width: 132px;
}

select,
input,
button {
    height: 36px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    font: inherit;
}

select,
input {
    padding: 0 10px;
    max-width: 100%;
}

select[multiple] {
    height: 76px;
    min-width: 260px;
    padding: 6px 8px;
}

button {
    padding: 0 14px;
    border-color: var(--accent);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
}

button.secondary {
    border-color: var(--line);
    background: #fff;
    color: var(--ink);
}

.inline-edit {
    display: flex;
    align-items: end;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.inline-edit input {
    min-width: 220px;
}

.settings-form {
    display: grid;
    gap: 18px;
}

.settings-panel {
    margin-bottom: 18px;
}

.settings-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.settings-heading form {
    margin: 0;
}

.settings-login-wrap {
    display: grid;
    place-items: start center;
    padding-top: 36px;
}

.settings-login {
    width: min(420px, 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 22px;
    box-shadow: 0 14px 34px rgba(24, 32, 42, 0.08);
}

.settings-login p {
    margin-bottom: 18px;
}

.form-error {
    margin-bottom: 14px;
    border: 1px solid rgba(187, 90, 33, 0.36);
    border-radius: 6px;
    background: rgba(187, 90, 33, 0.08);
    color: #8a3d11;
    padding: 10px 12px;
}

.settings-panel p {
    margin-bottom: 12px;
}

.settings-panel small {
    display: block;
    max-width: 520px;
    overflow-wrap: anywhere;
    color: var(--muted);
    font-weight: 400;
}

.table-form input {
    min-width: 220px;
}

.settings-form fieldset {
    margin: 0;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.settings-form legend {
    padding: 0 6px;
    color: var(--accent);
    font-weight: 800;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(260px, 1fr));
    gap: 14px;
}

.settings-grid label {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
}

.settings-grid span {
    color: var(--ink);
    font-weight: 700;
}

.settings-grid input {
    width: 160px;
}

.settings-grid small {
    color: var(--muted);
    line-height: 1.35;
}

.tabs {
    display: flex;
    gap: 4px;
    padding: 10px 28px 0;
    background: var(--panel);
    overflow-x: auto;
    scrollbar-width: thin;
}

.tabs a {
    flex: 0 0 auto;
    padding: 10px 14px;
    border: 1px solid transparent;
    border-bottom: 0;
    border-radius: 6px 6px 0 0;
    color: var(--muted);
    text-decoration: none;
}

.tabs a.active {
    border-color: var(--line);
    background: var(--bg);
    color: var(--ink);
}

main {
    padding: 24px 28px 40px;
    min-width: 0;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 22px;
}

.metrics article,
section > div,
section:not(.metrics):not(.split) {
    min-width: 0;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.metrics article {
    padding: 16px;
}

.metrics span {
    display: block;
    color: var(--muted);
}

.metrics strong {
    display: block;
    margin-top: 6px;
    font-size: 28px;
}

.split {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(340px, .65fr);
    gap: 18px;
}

.split > div {
    min-width: 0;
}

section > div,
section:not(.metrics):not(.split) {
    padding: 16px;
}

.table-wrap {
    overflow: auto;
    max-width: 100%;
    padding: 0;
    border-radius: 8px;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

.sessions-table {
    border-collapse: separate;
    border-spacing: 0;
    background: var(--panel);
}

.sessions-table th:first-child,
.sessions-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 2;
    width: 96px;
    min-width: 96px;
    max-width: 96px;
    background-color: var(--panel);
}

.sessions-table th:nth-child(2),
.sessions-table td:nth-child(2) {
    position: sticky;
    left: 96px;
    z-index: 2;
    background-color: var(--panel);
    box-shadow: 1px 0 0 var(--line);
}

.sessions-table th:first-child,
.sessions-table th:nth-child(2) {
    z-index: 3;
}

th,
td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    white-space: nowrap;
}

tbody tr:hover {
    background: #fbfcfd;
}

th {
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    font-weight: 650;
    user-select: none;
}

th::after {
    content: "<>";
    display: inline-block;
    margin-left: 5px;
    color: #9aa6b4;
    font-size: 10px;
}

th[data-sort-direction="asc"]::after {
    content: "^";
    color: var(--accent);
}

th[data-sort-direction="desc"]::after {
    content: "v";
    color: var(--accent);
}

td.rank {
    width: 44px;
    color: var(--accent-2);
    font-weight: 700;
}

.pace {
    color: var(--good);
    font-weight: 700;
}

.entity-link {
    color: var(--accent);
    font-weight: 700;
    text-decoration: none;
}

.entity-link:hover {
    text-decoration: underline;
}

.score {
    color: var(--accent);
    font-weight: 800;
}

.detail-metrics {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.detail-metrics article {
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
}

.detail-metrics span {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.detail-metrics strong {
    display: block;
    margin-top: 4px;
    font-size: 18px;
}

.detail-table {
    margin-top: 10px;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
    color: var(--muted);
}

.pagination > div {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pagination a {
    padding: 7px 10px;
    border: 1px solid var(--accent);
    border-radius: 6px;
    color: var(--accent);
    font-weight: 700;
    text-decoration: none;
}

.pagination a:hover {
    background: #edf7f6;
}

.empty {
    padding: 20px;
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 8px;
}

.error {
    max-width: 840px;
    margin: 32px auto;
    padding: 20px;
    background: #fff;
    border: 1px solid #e3b7a3;
    border-radius: 8px;
}

.error code {
    display: block;
    overflow: auto;
    margin-top: 12px;
    padding: 12px;
    background: #f8ece6;
}

@media (max-width: 850px) {
    .topbar {
        align-items: stretch;
        flex-direction: column;
        gap: 16px;
        padding: 18px 16px 12px;
    }

    .split,
    .settings-grid {
        grid-template-columns: 1fr;
    }

    .filters {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        justify-content: stretch;
    }

    .filter-panel summary {
        justify-content: flex-start;
    }

    .filters label,
    .filters button,
    .inline-edit label,
    .inline-edit button {
        min-width: 0;
        width: 100%;
    }

    .filters select,
    .filters input,
    .filters button,
    .inline-edit input,
    .inline-edit button {
        width: 100%;
    }

    select[multiple] {
        min-width: 0;
    }

    .tabs {
        padding: 8px 16px 0;
    }

    main {
        padding: 18px 16px 32px;
    }

    .metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .detail-metrics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .metrics article {
        padding: 14px;
    }

    .metrics strong {
        font-size: 23px;
    }

    section > div,
    section:not(.metrics):not(.split) {
        padding: 14px;
    }

    table {
        min-width: 680px;
    }

    th,
    td {
        padding: 9px 7px;
    }

    th:first-child,
    td:first-child {
        position: sticky;
        left: 0;
        z-index: 1;
        width: 52px;
        min-width: 52px;
        max-width: 52px;
        background: var(--panel);
    }

    th:nth-child(2),
    td:nth-child(2) {
        position: sticky;
        left: 52px;
        z-index: 1;
        max-width: 150px;
        overflow: hidden;
        background: var(--panel);
        box-shadow: 1px 0 0 var(--line);
        text-overflow: ellipsis;
    }

    th:first-child,
    th:nth-child(2) {
        z-index: 2;
    }

    .sessions-table th:first-child,
    .sessions-table td:first-child {
        width: 96px;
        min-width: 96px;
        max-width: 96px;
    }

    .sessions-table {
        border-collapse: separate;
        border-spacing: 0;
        background: var(--panel);
    }

    .sessions-table th:first-child,
    .sessions-table td:first-child,
    .sessions-table th:nth-child(2),
    .sessions-table td:nth-child(2) {
        background-color: var(--panel);
    }

    .sessions-table th:nth-child(2),
    .sessions-table td:nth-child(2) {
        left: 96px;
    }
}

@media (max-width: 560px) {
    body {
        font-size: 13px;
    }

    h1 {
        font-size: 20px;
    }

    .topbar p {
        overflow-wrap: anywhere;
    }

    .filters {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    select,
    input,
    button {
        height: 40px;
    }

    select[multiple] {
        height: 92px;
    }

    .tabs a {
        padding: 10px 12px;
    }

    .metrics,
    .detail-metrics {
        gap: 8px;
    }

    .metrics article,
    .detail-metrics article {
        padding: 10px;
    }

    .detail-metrics strong {
        font-size: 15px;
        overflow-wrap: anywhere;
    }

    table {
        min-width: 620px;
    }

    .settings-form fieldset {
        padding: 12px;
    }

    .settings-grid label {
        padding: 10px;
    }

    .settings-grid input {
        width: 100%;
    }
}
