/*
 * The admin panel's styles. The colours are those of the Deltarank web app
 * (deltarank-frontend/css/tokens.css): dark by default, light when the
 * device prefers it. The pages run no scripts, so the theme follows the
 * device rather than a toggle.
 */

/* ---------- Tokens ---------- */

:root {
    color-scheme: dark;

    --bg: #080a0d;
    --bg-raised: #0d1014;
    --surface: #12161b;
    --surface-hover: #181d24;
    --surface-active: #1f252e;
    --border: #1a2027;
    --border-strong: #28303a;
    --border-hover: #38424f;

    --text-strong: #ffffff;
    --text: #e9ecf0;
    --text-muted: #8d97a5;
    --text-faint: #5c6572;
    --on-accent: #0b0f17;

    --accent: #7aa7ff;
    --accent-soft: rgba(122, 167, 255, 0.16);
    --up: #3ddc97;
    --up-soft: rgba(61, 220, 151, 0.15);
    --down: #ff6b6b;
    --down-soft: rgba(255, 107, 107, 0.15);
    --warning: #f5b94a;
    --warning-soft: rgba(245, 185, 74, 0.14);
    --warning-text: #e9d3a6;
    --selection: rgba(122, 167, 255, 0.3);

    --radius: 12px;
    --radius-sm: 8px;

    --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-display: "Bricolage Grotesque", "Geist", ui-sans-serif, system-ui, sans-serif;
    --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
    :root {
        color-scheme: light;

        --bg: #ffffff;
        --bg-raised: #f6f8fa;
        --surface: #ffffff;
        --surface-hover: #f1f4f7;
        --surface-active: #e9edf2;
        --border: #e6e9ee;
        --border-strong: #d5dbe2;
        --border-hover: #b7c0cb;

        --text-strong: #000000;
        --text: #0f141a;
        --text-muted: #56606d;
        --text-faint: #7d8693;
        --on-accent: #ffffff;

        --accent: #2259d8;
        --accent-soft: rgba(34, 89, 216, 0.12);
        --up: #037a50;
        --up-soft: rgba(3, 122, 80, 0.11);
        --down: #c8283a;
        --down-soft: rgba(200, 40, 58, 0.1);
        --warning: #c27c06;
        --warning-soft: rgba(194, 124, 6, 0.12);
        --warning-text: #6f4304;
        --selection: rgba(34, 89, 216, 0.18);
    }
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }

html {
    -webkit-text-size-adjust: 100%;
    scrollbar-color: var(--border-strong) transparent;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 var(--font-sans);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

::selection { background: var(--selection); color: var(--text-strong); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

h1, h2 { color: var(--text-strong); font-family: var(--font-display); font-weight: 650; letter-spacing: -0.01em; }
h1 { margin: 0; font-size: 26px; line-height: 1.2; }
h2 { margin: 0 0 12px; font-size: 17px; }

p { margin: 0 0 12px; }

.mono { font-family: var(--font-mono); font-size: 13px; font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.nowrap { white-space: nowrap; }
.up { color: var(--up); }
.down { color: var(--down); }

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 12px;
    z-index: 10;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--on-accent);
}
.skip-link:focus { top: 12px; }

/* ---------- Header ---------- */

.site-header {
    position: sticky;
    top: 0;
    z-index: 5;
    border-bottom: 1px solid var(--border);
    background: color-mix(in srgb, var(--bg) 88%, transparent);
    backdrop-filter: saturate(1.4) blur(12px);
}

.header-inner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 24px;
    max-width: 1440px;
    margin: 0 auto;
    padding: 10px 24px;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--text-strong);
    font: 650 17px/1 var(--font-display);
}
.brand:hover { text-decoration: none; }
.brand-mark rect { fill: var(--accent); }
.brand-mark path { stroke: var(--on-accent); }
.brand-mark circle { fill: var(--on-accent); }
.brand-tag {
    padding: 3px 7px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    color: var(--text-muted);
    font: 500 11px/1 var(--font-sans);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.site-nav { flex: 1 1 auto; }
.site-nav ul { display: flex; flex-wrap: wrap; gap: 2px; margin: 0; padding: 0; list-style: none; }
.site-nav a {
    display: block;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-weight: 500;
}
.site-nav a:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.site-nav a[aria-current="page"] { background: var(--surface-active); color: var(--text-strong); }

.account { display: flex; align-items: center; gap: 10px; }
.account-link { display: inline-flex; align-items: center; gap: 8px; color: var(--text); }
.account-link[aria-current="page"] .account-name { color: var(--accent); }

/* ---------- Page ---------- */

.page { max-width: 1440px; margin: 0 auto; padding: 24px 24px 64px; }

.page-header { margin-bottom: 20px; }
.crumbs ol { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; padding: 0; list-style: none; font-size: 13px; }
.crumbs li + li::before { content: "›"; margin-right: 6px; color: var(--text-faint); }
.crumbs a { color: var(--text-muted); }
.title-row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
.subheading { margin: 6px 0 0; color: var(--text-muted); }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.lead { max-width: 80ch; color: var(--text-muted); }
.hint { margin-top: -8px; color: var(--text-faint); font-size: 13px; }
.empty { padding: 20px; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--text-muted); text-align: center; }

.section-title { margin-top: 32px; }
.section-heading { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin: 32px 0 12px; }
.section-heading h2 { margin: 0; }

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

.panel {
    margin: 16px 0;
    padding: 16px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-raised);
}
.panel > summary { cursor: pointer; color: var(--text-strong); font-weight: 600; }
.panel[open] > summary { margin-bottom: 12px; }
.panel-heading { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px 16px; margin-bottom: 12px; }
.panel-heading h2 { margin: 0; }

.facts { display: flex; flex-wrap: wrap; gap: 8px 32px; margin: 0 0 20px; }
.facts dt { color: var(--text-muted); font-size: 12px; }
.facts dd { margin: 2px 0 0; color: var(--text-strong); font-weight: 500; }

/* ---------- Tabs ---------- */

.tabs { margin-bottom: 24px; border-bottom: 1px solid var(--border); }
.tabs ul { display: flex; flex-wrap: wrap; gap: 4px; margin: 0; padding: 0; list-style: none; }
.tabs a {
    display: block;
    margin-bottom: -1px;
    padding: 8px 12px;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-weight: 500;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a[aria-current="page"] { border-bottom-color: var(--accent); color: var(--text-strong); }

/* ---------- Notices and messages ---------- */

.notices { display: grid; gap: 8px; margin-bottom: 20px; }

.notice {
    margin: 0;
    padding: 10px 14px;
    border: 1px solid var(--border-strong);
    border-left-width: 3px;
    border-radius: var(--radius-sm);
    background: var(--surface);
}
.notice-success { border-left-color: var(--up); background: var(--up-soft); }
.notice-info { border-left-color: var(--accent); background: var(--accent-soft); }
.notice-warning { border-left-color: var(--warning); background: var(--warning-soft); }
.notice-error { border-left-color: var(--down); background: var(--down-soft); }

.message {
    margin: 0 0 20px;
    padding: 14px 16px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface);
}
.message h2 { margin-bottom: 6px; font-size: 15px; }
.message p:last-child, .message ul:last-child { margin-bottom: 0; }
.message ul { margin: 0; padding-left: 20px; }
.message-info { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); background: var(--accent-soft); }
.message-warning { border-color: color-mix(in srgb, var(--warning) 45%, var(--border)); background: var(--warning-soft); }
.message-warning h2 { color: var(--warning-text); }
.message-error { border-color: color-mix(in srgb, var(--down) 45%, var(--border)); background: var(--down-soft); }

/* ---------- Buttons ---------- */

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 36px;
    padding: 0 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: 500 14px/1 var(--font-sans);
    white-space: nowrap;
    cursor: pointer;
}
.button:hover { border-color: var(--border-hover); background: var(--surface-hover); text-decoration: none; }
.button.primary { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
.button.primary:hover { background: color-mix(in srgb, var(--accent) 88%, var(--text-strong)); }
.button.danger { border-color: color-mix(in srgb, var(--down) 50%, var(--border-strong)); color: var(--down); }
.button.danger:hover { background: var(--down-soft); }
.button.subtle { border-color: transparent; background: transparent; color: var(--text-muted); }
.button.subtle:hover { background: var(--surface-hover); color: var(--text); }
.button.small { min-height: 28px; padding: 0 10px; font-size: 13px; }
.button.wide { width: 100%; }

.inline-form { display: inline; margin: 0; }

.badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--surface-active);
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.02em;
    vertical-align: middle;
}
.badge.danger { background: var(--down-soft); color: var(--down); }

.state {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--surface-active);
    color: var(--text-muted);
    font: 500 12px/1.5 var(--font-mono);
}
.state-collecting { background: var(--up-soft); color: var(--up); }
.state-failing, .state-access_denied { background: var(--down-soft); color: var(--down); }
.state-starting, .state-no_spot_markets { background: var(--warning-soft); color: var(--warning-text); }

.state-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.state-list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.state-list .count { color: var(--text-strong); font-variant-numeric: tabular-nums; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.chips a { display: block; padding: 4px 10px; border: 1px solid var(--border-strong); border-radius: 999px; color: var(--text); }
.chips a:hover { border-color: var(--border-hover); text-decoration: none; }

/* ---------- Dashboard ---------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-raised);
    color: var(--text);
}
.tile:hover { border-color: var(--border-hover); text-decoration: none; }
.tile-label { color: var(--text-muted); font-size: 13px; }
.tile-value { color: var(--text-strong); font: 650 26px/1.15 var(--font-display); font-variant-numeric: tabular-nums; }
.tile-note { color: var(--text-faint); font-size: 12px; }

/* ---------- Tables ---------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-raised); }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
thead th {
    position: sticky;
    top: 0;
    background: var(--bg-raised);
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}
tbody tr:last-child th, tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-hover); }
td .muted { margin-left: 6px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions { width: 1%; text-align: right; white-space: nowrap; }
.user-agent { max-width: 360px; overflow-wrap: anywhere; color: var(--text-muted); font-size: 12px; }

table.compact th, table.compact td { padding: 6px 0; }
table.compact th:last-child, table.compact td:last-child { text-align: right; }

/* ---------- Filters ---------- */

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-bottom: 16px; }
.filters .field { margin: 0; }
.filters input, .filters select { min-width: 180px; }

/* ---------- Forms ---------- */

.record-form { margin-bottom: 24px; }

.form-section {
    margin: 0 0 16px;
    padding: 16px 18px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-raised);
}
.form-section legend { padding: 0 6px; margin-left: -6px; color: var(--text-strong); font-weight: 600; }
.section-description { color: var(--text-muted); font-size: 13px; }

.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 4px 20px; }

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field > label { color: var(--text); font-weight: 500; }
.required { color: var(--down); }

input[type="text"], input[type="search"], input[type="password"], select, textarea {
    width: 100%;
    min-height: 36px;
    padding: 7px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    font: 14px/1.4 var(--font-sans);
}
input.mono, textarea.mono { font-family: var(--font-mono); font-size: 13px; }
textarea { resize: vertical; font-family: var(--font-mono); font-size: 13px; }
input:hover, select:hover, textarea:hover { border-color: var(--border-hover); }
input:focus-visible, select:focus-visible, textarea:focus-visible { border-color: var(--accent); outline: 2px solid var(--accent-soft); outline-offset: 0; }
input:disabled, select:disabled, textarea:disabled { border-style: dashed; color: var(--text); opacity: 1; cursor: default; }
::placeholder { color: var(--text-faint); }

.input-row { display: flex; align-items: center; gap: 8px; }
.unit { flex: none; color: var(--text-muted); font-size: 12px; font-weight: 500; }

.help { margin: 0; color: var(--text-muted); font-size: 12px; }
.field-error { margin: 0; color: var(--down); font-size: 13px; font-weight: 500; }
.field-conflict { margin: 0; color: var(--warning-text); font-size: 13px; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--down); }
.has-conflict input, .has-conflict select, .has-conflict textarea { border-color: var(--warning); background: var(--warning-soft); }

.field-checkbox { justify-content: center; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px 16px; padding-bottom: 12px; }
.checkbox-grid .checkbox { padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.checkbox-grid .checkbox .muted { margin-left: auto; font-size: 12px; }

.overwrite {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    padding: 10px 14px;
    border: 1px solid color-mix(in srgb, var(--warning) 45%, var(--border));
    border-radius: var(--radius-sm);
    background: var(--warning-soft);
}

.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

input[type="file"] {
    width: 100%;
    padding: 6px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text-muted);
    font: 14px/1.4 var(--font-sans);
}
input[type="file"]::file-selector-button {
    margin-right: 12px;
    padding: 6px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    cursor: pointer;
}
input[type="file"]::file-selector-button:hover { border-color: var(--border-hover); background: var(--surface-hover); }
.has-error input[type="file"] { border-color: var(--down); }

/* ---------- Logos ---------- */

/* The stored logo on a checkerboard, which shows where it is transparent. */
.logo-preview { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 20px 40px; margin: 0 0 20px; }
.logo-preview figure { display: grid; justify-items: start; gap: 8px; margin: 0; }
.logo-preview figcaption { color: var(--text-muted); font-size: 12px; }
.logo-stored {
    display: block;
    width: 128px;
    height: 128px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: repeating-conic-gradient(var(--surface-active) 0 25%, var(--bg-raised) 0 50%) 0 0 / 16px 16px;
}

/* As the site shows logos: always circles, cropped rather than stretched. The
   ring outlines the circle, which a logo with a background like the page's hides. */
.logo-circles { display: flex; align-items: center; gap: 16px; min-height: 96px; }
.logo-circle { display: block; flex: none; border-radius: 50%; object-fit: cover; box-shadow: 0 0 0 1px var(--border-strong); }
.logo-circle-24 { width: 24px; height: 24px; }
.logo-circle-40 { width: 40px; height: 40px; }
.logo-circle-96 { width: 96px; height: 96px; }

/* ---------- Confirmations ---------- */

.confirm {
    max-width: 720px;
    padding: 18px 20px;
    border: 1px solid color-mix(in srgb, var(--down) 40%, var(--border));
    border-radius: var(--radius);
    background: var(--bg-raised);
}
.consequences { margin: 0 0 18px; padding-left: 20px; }
.consequences li + li { margin-top: 6px; }

/* ---------- Audit log ---------- */

.audit-entries { margin: 0; padding: 0; list-style: none; }
.audit-entry { padding: 12px 0; border-bottom: 1px solid var(--border); }
.audit-entry:last-child { border-bottom: 0; }
.audit-summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; }
.audit-time { color: var(--text-muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.audit-user { color: var(--text-strong); font-weight: 600; }
.audit-subject .muted { margin-right: 4px; }
.audit-details { margin-top: 8px; padding-left: 12px; border-left: 2px solid var(--border-strong); }
.audit-details p { margin: 4px 0; font-size: 13px; }
.audit-details details summary { cursor: pointer; color: var(--text-muted); font-size: 13px; }
table.changes { width: auto; max-width: 100%; margin: 4px 0; font-size: 13px; }
table.changes th, table.changes td { padding: 4px 16px 4px 0; overflow-wrap: anywhere; }
table.changes thead th { position: static; background: none; }
table.changes tbody tr:hover { background: none; }
dl.values { display: grid; grid-template-columns: max-content 1fr; gap: 2px 16px; margin: 6px 0; font-size: 13px; }
dl.values dt { color: var(--text-muted); }
dl.values dd { margin: 0; overflow-wrap: anywhere; }

dl.roles { display: grid; gap: 8px; margin: 0; }
dl.roles dt { color: var(--text-strong); font-weight: 600; }
dl.roles dd { margin: 0; color: var(--text-muted); }

/* ---------- Pagination ---------- */

.pagination { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }
.pagination-status { margin: 0; color: var(--text-muted); font-size: 13px; }
.pagination ul { display: flex; align-items: center; gap: 8px; margin: 0; padding: 0; list-style: none; }
.pagination-page { color: var(--text-muted); font-size: 13px; }

/* ---------- Sign-in and error pages ---------- */

.sign-in {
    max-width: 380px;
    margin: 8vh auto 0;
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-raised);
}
.sign-in h1 { margin-bottom: 18px; }
.sign-in .notice { margin-bottom: 16px; }
.sign-in-form .button { margin-top: 6px; }

.error-page { max-width: 640px; margin: 8vh auto 0; text-align: center; }
.error-status { margin: 0 0 8px; color: var(--text-faint); font: 650 48px/1 var(--font-display); }
.error-page h1 { margin-bottom: 12px; }
.error-page p { color: var(--text-muted); }

.plain-page { max-width: 640px; margin: 12vh auto 0; padding: 0 24px; text-align: center; }
.plain-page p { color: var(--text-muted); }

/* ---------- Small screens ---------- */

@media (max-width: 760px) {
    .header-inner, .page { padding-left: 14px; padding-right: 14px; }
    .site-nav { order: 3; flex-basis: 100%; }
    .account { margin-left: auto; }
    .fields { grid-template-columns: 1fr; }
    .filters input, .filters select { min-width: 0; }
    .filters .field { flex: 1 1 140px; }
}
