/* css/admin.css — the private /admin page. Tokens from styles.css only, so
   light and dark are handled automatically. */

/* --- Route visibility --------------------------------------------------- */
/* Mirrors guide.css and bingo.css: AdminView toggles body.route-admin and CSS
   owns the swap. */
#adminView { display: none; }
body.route-admin .table-container,
body.route-admin #tableFooter { display: none; }
body.route-admin #adminView { display: block; }

/* --- Page --------------------------------------------------------------- */
.admin-view { padding: 1.5rem 16px 3rem; }

.admin {
    max-width: 72rem;
    margin: 0 auto;
    color: var(--surface-9);
    line-height: 1.6;
}

.admin h1 { font-size: 1.9rem; margin: 0 0 1rem; }
/* Headings are programmatic focus targets (tabindex="-1") reached by route
   entry or a sub-menu jump, never by Tab, so no ring. */
.admin h1:focus, .admin h2:focus { outline: none; }
.admin h2 {
    font-size: 1.3rem;
    margin: 0 0 0.5rem;
    color: var(--brand-3);
}

/* How far below the viewport top a jumped-to section must land so a sticky
   sub-menu never covers its heading. The nav styles set it per layout. */
:root { --admin-nav-offset: 0px; }

.admin-section {
    padding: 1rem 0 1.5rem;
    border-top: 1px solid var(--surface-5);
    scroll-margin-top: var(--admin-nav-offset);
}
.admin-section:first-child { border-top: none; }

.admin-placeholder { color: var(--surface-8); margin: 0; }

/* --- Roles section (components/admin/RolesSection.js) --------------------- */
/* The search field itself is the header's .search-box, reused as-is. */

/* Errors read left-aligned here, unlike the edit forms' right-aligned ones. */
.admin-roles-error, .admin-user-error, .admin-flags-error, .admin-flag-error, .admin-block-error, .admin-bingo-error, .admin-announcement-error { text-align: left; padding: 0; margin: 0.5rem 0 0; }
.admin-roles-error:not(.is-visible), .admin-user-error:not(.is-visible),
.admin-flags-error:not(.is-visible), .admin-flag-error:not(.is-visible),
.admin-block-error:not(.is-visible), .admin-bingo-error:not(.is-visible),
.admin-announcement-error:not(.is-visible) { display: none; }
.admin-roles-hint, .admin-flags-hint { color: var(--surface-8); margin: 0.5rem 0 0; }
.admin-roles-hint:empty, .admin-flags-hint:empty { display: none; }

.admin-user-list { list-style: none; margin: 0.5rem 0 0; padding: 0; }
/* Rows stack (identity above controls) so narrow screens never overflow. */
.admin-user {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.6rem 0;
    border-top: 1px solid var(--surface-5);
}
/* No rule between the search bar and the first result. */
.admin-user:first-child { border-top: none; }
.admin-user-identity { display: flex; flex-wrap: wrap; gap: 0.25rem 0.75rem; align-items: baseline; }
.admin-user-identity > * { min-width: 0; overflow-wrap: anywhere; }
.admin-user-email { color: var(--surface-8); }
.admin-user-unverified { color: var(--error-inline); font-size: 0.85rem; }
.admin-user-controls { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; align-items: center; }
.admin-user-controls label { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; }

/* --- Flags section (components/admin/FlagsSection.js) ----------------------
   Rows reuse the Roles list's stacked look so they never overflow at 375px. */
.admin-flag-list { list-style: none; margin: 0.5rem 0 0; padding: 0; }
.admin-flag {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.6rem 0;
    border-top: 1px solid var(--surface-5);
}
.admin-flag:first-child { border-top: none; }
.admin-flag-head { display: flex; flex-wrap: wrap; gap: 0.25rem 0.75rem; align-items: baseline; }
.admin-flag-head > * { min-width: 0; overflow-wrap: anywhere; }
.admin-flag-description { margin: 0; color: var(--surface-8); overflow-wrap: anywhere; }
.admin-flag-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.admin-flag-actions:empty { display: none; }
.admin-flag-actions button:disabled { opacity: 0.6; cursor: default; }

/* State badge: Off is muted, Beta borrows the warning pair (in-progress),
   Live the approval pair (green, like Beta's soft tint). */
.admin-flag-state {
    padding: 0.05rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: bold;
    border: 1px solid transparent;
}
.admin-flag-state.is-off { background: var(--surface-4); color: var(--surface-8); border-color: var(--surface-5); }
.admin-flag-state.is-beta,
.admin-flag-state.is-hidden { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); }
.admin-flag-state.is-live { background: var(--approval-bg); color: var(--approval-text); border-color: var(--approval-border); }

/* Shared by the kill switch and the Pageviews blocks: every admin disclosure
   reads the same way. */
.admin-flag-emergency summary, .admin-block > summary, .admin-announcement-hints > summary { cursor: pointer; color: var(--surface-8); }
.admin-flag-emergency[open] summary, .admin-announcement-hints[open] summary { margin-bottom: 0.5rem; }

/* A Font Awesome angle replaces the native triangle so the arrow can turn
   smoothly: the marker is hidden and the icon rotates a quarter turn on open. */
.admin-flag-emergency > summary, .admin-block > summary, .admin-announcement-hints > summary {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.admin-flag-emergency > summary::-webkit-details-marker, .admin-block > summary::-webkit-details-marker, .admin-announcement-hints > summary::-webkit-details-marker { display: none; }
.admin-disclosure-icon { transition: transform 0.2s ease; }
details[open] > summary > .admin-disclosure-icon { transform: rotate(90deg); }
@media (prefers-reduced-motion: reduce) { .admin-disclosure-icon { transition: none; } }

/* Emergency is the one disclosure that pulls something back, so it wears the
   warning colour; the icon inherits it from the summary. */
.admin-flag-emergency > summary { color: var(--warning-text); }

/* --- Pageviews section (components/admin/PageviewsSection.js) -------------
   Each block is a PollingPanel <details>; collapsed means no requests. */
.admin-block {
    margin: 0.5rem 0 0;
    padding: 0.5rem 0.75rem;
    border-top: 1px solid var(--surface-5);
}
/* The brand colour marks these as the clickable headers; the icon follows
   the text so the pair reads as one control. */
.admin-block > summary { color: var(--brand-2); }
.admin-block-title { color: var(--brand-2); font-weight: bold; }
.admin-block-updated { color: var(--surface-8); font-size: 0.85rem; }
.admin-block-body:not(:empty) { margin-top: 0.5rem; }
.admin-viewers p { margin: 0 0 0.25rem; overflow-wrap: anywhere; }
.admin-viewers-pages { color: var(--surface-8); }

/* Heatmap (components/admin/Heatmap.js). The step is one cell plus its gap;
   the SVG's viewBox is in steps, so this one variable sizes the whole chart.
   The scroll box is the shared .table-wrapper, and the JS scrolls it to the
   latest weeks, which is what a phone should see first. */
.admin-heatmap { --heatmap-step: 14px; }
@media (max-width: 480px) { .admin-heatmap { --heatmap-step: 12px; } }
.admin-heatmap:not(:empty) { margin-top: 0.75rem; }
.admin-heatmap-headline { margin: 0 0 0.25rem; font-weight: bold; overflow-wrap: anywhere; }
.admin-heatmap-svg {
    display: block;
    width: calc(var(--heatmap-cols) * var(--heatmap-step));
    height: calc(7 * var(--heatmap-step));
}
/* Five levels from the muted surface to the brand colour. Both tokens flip
   with the OS theme, so the mix follows without any JS. */
.admin-heatmap-cell.is-l0 { fill: var(--surface-4); }
.admin-heatmap-cell.is-l1 { fill: color-mix(in srgb, var(--surface-4), var(--brand-3) 25%); }
.admin-heatmap-cell.is-l2 { fill: color-mix(in srgb, var(--surface-4), var(--brand-3) 50%); }
.admin-heatmap-cell.is-l3 { fill: color-mix(in srgb, var(--surface-4), var(--brand-3) 75%); }
.admin-heatmap-cell.is-l4 { fill: var(--brand-3); }
/* Pills are the filter bar's .filter-chip (and the row its .filter-chips);
   only the pressed state is new, borrowing the sort menu's brand-text look. */
.admin-heatmap-pills { margin-top: 0.5rem; }
.admin-heatmap-pill.is-active { color: var(--brand-3); border-color: var(--brand-3); font-weight: bold; }

/* The data table's look (styles.css) without what only the species list
   needs: no 600px floor (the wrapper scrolls if a name is long), no sticky or
   clickable headers, no row hover, and tighter cells for a short panel. */
/* Separate (not collapsed) borders so the header row's outer corners can be
   rounded: border-radius is not honoured on cells under border-collapse. */
.admin-table { min-width: 0; border-collapse: separate; border-spacing: 0; }
.admin-table th, .admin-table td { padding: 0.4rem 0.75rem; }
.admin-table th { position: static; cursor: auto; }
/* Undo the data table's header hover dimming: these headers aren't clickable. */
.admin-table th:hover { opacity: 1; }
.admin-table thead th { background-color: var(--surface-3); font-weight: bold; }
.admin-table thead th:first-child { border-top-left-radius: 0.5rem; }
.admin-table thead th:last-child { border-top-right-radius: 0.5rem; }
.admin-table tr:hover { background-color: transparent; cursor: auto; }
.admin-table td:not(.is-num) { overflow-wrap: anywhere; }
.admin-table .is-num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.admin-table tfoot th, .admin-table tfoot td { background: none; color: inherit; font-weight: bold; border-bottom: none; white-space: normal; }
.admin-table-note { color: var(--surface-8); font-weight: normal; }

/* --- Bingo section (components/admin/BingoSection.js) ---------------------
   The table scrolls inside .admin-bingo-scroll (a .table-wrapper with a height
   cap) so a long list never stretches the page. Column headers pin at the top
   and the current user's header pins just under them; each user is its own
   <tbody>, so a group header lets go when its group ends. Both rows share one
   fixed height so the second sticky offset is known without measuring. */
.admin-bingo-toolbar { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center; }
.admin-bingo-hide { display: inline-flex; align-items: center; gap: 0.4rem; }
.admin-bingo-toolbar .admin-block-updated:empty { display: none; }
.admin-bingo-scroll { --admin-bingo-row: 2.5rem; max-height: 24rem; overflow: auto; margin-top: 0.5rem; }
.admin-bingo-empty { color: var(--surface-8); margin: 0; }
.admin-bingo-table thead th, .admin-bingo-table .admin-bingo-group {
    position: sticky;
    height: var(--admin-bingo-row);
    box-sizing: border-box;
    white-space: nowrap;
}
.admin-bingo-table thead th { top: 0; z-index: 2; }
.admin-bingo-table .admin-bingo-group {
    top: var(--admin-bingo-row);
    z-index: 1;
    background-color: var(--surface-4);
    text-align: left;
}
.admin-bingo-table td { white-space: nowrap; }

/* --- Sub-menu ------------------------------------------------------------
   One set of links (components/AdminNav.js) in two forms. Narrow: a sticky top
   bar that scrolls sideways rather than wrapping. Wide: a sticky left sidebar.
   The breakpoint must match WIDE_QUERY in AdminNav.js. The bar lives inside
   .admin-layout so sticky holds it for the whole run of sections. */
.admin-nav {
    position: sticky;
    top: 0;
    z-index: 5;
    margin: 0 -16px 1rem;
    padding: 0 16px;
    background: var(--surface-1);
    border-bottom: 1px solid var(--surface-5);
}
.admin-nav ul {
    display: flex;
    gap: 1.25rem;
    margin: 0;
    padding: 0;
    list-style: none;
    overflow-x: auto;
    white-space: nowrap;
}
.admin-nav a {
    display: block;
    padding: 0.75rem 0;
    color: var(--surface-8);
    text-decoration: none;
    border-bottom: 2px solid transparent;
}
.admin-nav a:hover { color: var(--surface-9); }
.admin-nav a.is-active {
    color: var(--brand-3);
    border-bottom-color: var(--brand-3);
}

@media (min-width: 50rem) {
    .admin-layout {
        display: grid;
        grid-template-columns: 9rem minmax(0, 1fr);
        gap: 2rem;
        align-items: start;
    }
    .admin-nav {
        top: 1rem;
        margin: 0;
        padding: 0;
        border-bottom: none;
        border-right: 1px solid var(--surface-5);
    }
    .admin-nav ul { flex-direction: column; gap: 0; overflow: visible; }
    .admin-nav a {
        padding: 0.4rem 1rem 0.4rem 0;
        border-bottom: none;
        border-right: 2px solid transparent;
        margin-right: -1px;
    }
    .admin-nav a.is-active { border-right-color: var(--brand-3); }
}

/* --- Announcement section (components/admin/AnnouncementSection.js) ------- */
/* The preview and rows reuse .guide-nudge and the flag state badge; only the
   composer layout and list spacing are new. */
.admin-announcement-composer { display: flex; flex-direction: column; gap: 0.5rem; }
.admin-announcement-input { width: 100%; min-height: 5rem; box-sizing: border-box; resize: vertical; font: inherit; }
.admin-announcement-meta { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; align-items: center; justify-content: space-between; }
.admin-announcement-counter.is-over { color: var(--error-inline); font-weight: bold; }
.admin-announcement-note { color: var(--surface-8); margin: 0; }
.admin-announcement-hints ul { margin: 0; padding-left: 1.5rem; color: var(--surface-8); }
.admin-announcement-hints li + li { margin-top: 0.25rem; }
.admin-announcement-note.is-error { color: var(--error-inline); }
.admin-announcement-preview .guide-nudge { margin: 0; }
.admin-announcement-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.admin-announcement-list { list-style: none; margin: 1rem 0 0; padding: 0; }
.admin-announcement {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    padding: 0.75rem 0;
    border-top: 1px solid var(--surface-5);
}
.admin-announcement:first-child { border-top: none; }
.admin-announcement-head { display: flex; flex-wrap: wrap; gap: 0.25rem 0.75rem; align-items: baseline; }
.admin-announcement-text { overflow-wrap: anywhere; white-space: pre-wrap; }
.admin-announcement-expiry { color: var(--surface-8); font-size: 0.85rem; }
.admin-announcement-row-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.admin-announcement-row-actions button:disabled { opacity: 0.6; cursor: default; }
