﻿:root {
    color-scheme: light;
    --background: #f8fafc;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #dfe4ea;
    --text: #1f2933;
    --text-muted: #66727f;
    --primary: #2563a8;
    --primary-hover: #1e4f87;
    --success: #237a45;
    --success-background: #e7f5ec;
    --warning: #98620c;
    --warning-background: #fff4d6;
    --danger: #b42318;
    --danger-hover: #8f1c12;
    --danger-background: #fce8e6;
    --info: #2563a8;
    --info-background: #e5eef8;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);

    /* Member Details activity heatmap - 0 (no/zero activity) through 4 (this member's own
       highest-activity day in the window), GitHub-contribution-graph style. Bucketed relative to
       the member's own data (see activityHeatmap.js's bucketFor), not an absolute XP threshold. */
    --heatmap-scale-0: #ebedf0;
    --heatmap-scale-1: #c6e6c1;
    --heatmap-scale-2: #8fd18a;
    --heatmap-scale-3: #4cae4c;
    --heatmap-scale-4: #237a45;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --background: #0f151b;
        --surface: #17212b;
        --surface-muted: #1c2731;
        --border: #2b3742;
        --text: #e6ebf0;
        --text-muted: #9aa7b2;
        --primary: #5b9bd9;
        --primary-hover: #7fb0e0;
        --success: #4caf7d;
        --success-background: #16332a;
        --warning: #d9a441;
        --warning-background: #3a2d10;
        --danger: #e5776d;
        --danger-hover: #f0968d;
        --danger-background: #3a1715;
        --info: #5b9bd9;
        --info-background: #16283a;
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);

        --heatmap-scale-0: #1c2731;
        --heatmap-scale-1: #164429;
        --heatmap-scale-2: #1c6b34;
        --heatmap-scale-3: #2f9e4c;
        --heatmap-scale-4: #4caf7d;
    }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --background: #0f151b;
    --surface: #17212b;
    --surface-muted: #1c2731;
    --border: #2b3742;
    --text: #e6ebf0;
    --text-muted: #9aa7b2;
    --primary: #5b9bd9;
    --primary-hover: #7fb0e0;
    --success: #4caf7d;
    --success-background: #16332a;
    --warning: #d9a441;
    --warning-background: #3a2d10;
    --danger: #e5776d;
    --danger-hover: #f0968d;
    --danger-background: #3a1715;
    --info: #5b9bd9;
    --info-background: #16283a;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);

    --heatmap-scale-0: #1c2731;
    --heatmap-scale-1: #164429;
    --heatmap-scale-2: #1c6b34;
    --heatmap-scale-3: #2f9e4c;
    --heatmap-scale-4: #4caf7d;
}

* {
    box-sizing: border-box;
}

html {
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--background);
}

body {
    margin: 0;
    min-width: 320px;
}

a {
    color: var(--primary);
}

input,
select,
textarea,
button {
    font: inherit;
}

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.app-body {
    flex: 1;
    display: grid;
    grid-template-columns: 230px minmax(0, 1fr);
    min-height: 0;
}

.button i,
.back-link i,
.page-header h1 i,
.panel-header h2 i,
.status-badge i {
    margin-right: 0.4rem;
}

.topbar {
    display: flex;
    flex: none;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    height: 56px;
    padding: 0 20px;
    color: #ffffff;
    background: #17212b;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.topbar-brand {
    font-size: 1.15rem;
    font-weight: 700;
    white-space: nowrap;
}

.topbar-clan {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-clan-icon {
    width: 26px;
    height: 26px;
    object-fit: contain;
    border-radius: 6px;
}

.topbar-status {
    color: #9aa7b2;
    font-size: 0.85rem;
    white-space: nowrap;
}

.topbar-status.connected {
    color: #6fd794;
}

.topbar-input {
    width: 220px;
    min-height: 34px;
    padding: 6px 10px;
    border: 1px solid #333f4a;
    border-radius: 4px;
    background: #0f151b;
    color: #e6ebf0;
}

.topbar-input::placeholder {
    color: #66727f;
}

.topbar-input:focus {
    border-color: var(--primary);
    outline: 2px solid rgba(37, 99, 168, 0.35);
}

.topbar-input[readonly] {
    color: #9aa7b2;
    background: #131b22;
}

.topbar-input.error {
    border-color: var(--danger);
}

.topbar-error {
    color: #ff9b93;
    font-size: 0.8rem;
}

.icon-button {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    padding: 0;
    border: none;
    border-radius: var(--radius);
    background: transparent;
    color: #d9e1e8;
    cursor: pointer;
}

.icon-button:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

.icon-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.icon-button-primary {
    color: #ffffff;
    background: var(--primary);
}

.icon-button-primary:hover {
    background: var(--primary-hover);
}

.icon-button-primary:disabled {
    background: var(--primary);
}

.sidebar {
    padding: 24px 16px;
    color: #ffffff;
    background: #17212b;
}

.sidebar-nav {
    display: grid;
    gap: 4px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 10px 12px;
    border-radius: var(--radius);
    color: #d9e1e8;
    text-decoration: none;
}

.sidebar-nav i {
    width: 1.25rem;
    text-align: center;
    opacity: .85;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

.main-content {
    min-width: 0;
    padding: 30px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

.page-header h1 {
    margin: 0;
    font-size: 1.75rem;
}

.page-subtitle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-muted);
}

.page-description {
    margin: 5px 0 0;
    color: var(--text-muted);
}

.clan-icon-preview {
    width: 34px;
    height: 34px;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* Unlike .clan-icon-preview (a small square avatar sitting inline in a header row), a standings
   chart is the whole point of its tab - shown as its own full-width block below the actions row
   (see Competition/Details.cshtml's #chartTabPanel) at close to its native render size (900px,
   matching CompetitionChartRenderer/StandingsChartRenderer's own ChartWidth), not squeezed into a
   thumbnail alongside the buttons. */
.chart-preview {
    display: block;
    width: 900px;
    max-width: 100%;
    height: auto;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.back-link {
    color: var(--text-muted);
    text-decoration: none;
}

.back-link:hover {
    color: var(--text);
    text-decoration: underline;
}

.panel {
    margin-bottom: 1.5rem;
    padding: 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.panel-header h2 {
    margin: 0;
    font-size: 1.125rem;
}

.panel-description {
    margin: 0.25rem 0 0;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.panel > .form-field + .form-field {
    margin-top: 1rem;
}

.field-validation-error {
    color: var(--danger);
    font-size: 0.85rem;
}

.validation-summary-valid {
    display: none;
}

.filter-bar {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 14px;
    margin-bottom: 18px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

.filter-bar select {
    max-width: 150px;
}

.form-field {
    display: grid;
    gap: 6px;
    min-width: 150px;
}

/* Equal specificity to the class rule above, but declared later, so this wins the cascade and
   restores the browser default that .form-field's own "display: grid" otherwise silently beats -
   without it, toggling the hidden attribute/property on a .form-field element does nothing. */
.form-field[hidden] {
    display: none;
}

.form-field-grow {
    flex: 1;
}

.filter-bar-summary {
    flex-basis: 100%;
    text-align: left;
}

.form-field label {
    font-size: 0.85rem;
    font-weight: 600;
}

.form-field input,
.form-field select,
.form-field textarea {
    width: 100%;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
    border-color: var(--primary);
    outline: 2px solid rgba(37, 99, 168, 0.15);
}

/* A form-field slot that's a link out to somewhere else rather than an editable value - e.g.
   ModelDetails.cshtml's "OpenAI Docs" field. Boxed the same height/padding as .form-field's own
   input/select/textarea so it lines up in a form-grid row; [aria-disabled] covers "no model
   picked yet" without a real <button disabled> (an <a> has no disabled attribute of its own). */
.form-field-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--primary);
    text-decoration: none;
}

.form-field-link:hover {
    background: var(--surface-muted);
}

.form-field-link[aria-disabled="true"] {
    color: var(--text-muted);
    pointer-events: none;
}

.form-actions {
    display: flex;
    gap: 8px;
}

/* Pagination footer below a list panel: page-size select on the left, prev/next nav on the
   right, both on the same row - see clanforge_pagination_control_split memory. */
.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 16px;
    margin-top: 1rem;
}

.page-size-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-size-select {
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
}

/* Sits between Previous/Next in .pagination-nav, replacing the old plain "Page X of Y" label -
   same look as .page-size-select but its own class since the two are populated differently
   (fixed sizes vs. one option per page) - see renderPageJumpOptions in core/utils.js. */
.page-jump-select {
    min-height: 38px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
}

.pagination-nav {
    display: flex;
    align-items: center;
    gap: 8px;
}

.button {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
}

/* Same gotcha as .form-field[hidden] elsewhere in this file: .button's own "display: inline-flex"
   is an author-stylesheet rule, so it silently beats the browser's default "[hidden] { display:
   none }" UA rule - toggling the hidden attribute/property on a .button element otherwise does
   nothing. Already known and worked around per call site with a redundant inline style rather
   than fixed here (see competition-details.js's setRemoveButtonHidden, and Event/Index.cshtml's
   "New Event" button) - found again via Competition Details' new Update button staying visible
   with hidden === true. Fixing it here properly, so a future .button doesn't need its own
   inline-style workaround (existing ones are unaffected - inline style wins regardless). */
.button[hidden] {
    display: none;
}

.button-primary {
    color: #ffffff;
    background: var(--primary);
}

.button-primary:hover {
    background: var(--primary-hover);
}

.button-secondary {
    color: var(--text);
    border-color: var(--border);
    background: var(--surface);
}

.table-container {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    color: var(--text-muted);
    background: var(--surface-muted);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.025em;
    text-transform: uppercase;
}

.data-table tbody tr:hover {
    background: var(--surface-muted);
}

.data-table tbody tr.row-selected {
    background: var(--success-background);
}

.data-table tbody tr:last-child td {
    border-bottom: 0;
}

.data-table tfoot td {
    border-top: 2px solid var(--border);
    border-bottom: 0;
    font-weight: 700;
}

/* Opt-in per-column sorting via wireSortableTable (core/utils.js) - click cycles a header
   ascending/descending, same arrow-glyph convention as the player app's .leagueTable
   th.sortable (blockbuster.css), just scoped to the admin .data-table class instead. */
.data-table th.sortable {
    cursor: pointer;
    user-select: none;
}

.data-table th.sortable:hover {
    background: var(--border);
}

.data-table th.sortable::after {
    content: "\2195";
    display: inline-block;
    margin-left: 4px;
    opacity: 0.35;
}

.data-table th.sortable.sort-asc::after {
    content: "\2191";
    opacity: 1;
}

.data-table th.sortable.sort-desc::after {
    content: "\2193";
    opacity: 1;
}

.table-link {
    font-weight: 600;
    text-decoration: none;
}

.table-link:hover {
    text-decoration: underline;
}

.secondary-text {
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.monospace {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.875rem;
}

.picker-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    align-items: start;
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.checkbox-column {
    width: 40px;
}

.key-reveal {
    display: flex;
    align-items: center;
    gap: 10px;
}

.key-reveal .dialog-detail {
    flex: 1;
    margin-top: 0;
}

.link-button {
    padding: 0;
    border: none;
    background: none;
    color: var(--primary);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}

.link-button:hover {
    text-decoration: underline;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin-bottom: 1rem;
}

.details-grid {
    display: grid;
    grid-template-columns: repeat(
        auto-fit,
        minmax(240px, 1fr)
    );
    gap: 1rem;
    margin: 0;
}

.details-item {
    padding: 0.875rem;
    background: var(--surface-muted);
    border-radius: 0.375rem;
}

.details-item dt {
    margin-bottom: 0.25rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.details-item dd {
    margin: 0;
    color: var(--text);
    overflow-wrap: anywhere;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 700;
}

.status-active {
    color: var(--success);
    background: var(--success-background);
}

.status-inactive {
    color: var(--danger);
    background: var(--danger-background);
}

.status-success {
    color: var(--success);
    background: var(--success-background);
}

.status-warning {
    color: var(--warning);
    background: var(--warning-background);
}

.status-danger {
    color: var(--danger);
    background: var(--danger-background);
}

.status-muted {
    color: var(--text-muted);
    background: var(--surface-muted);
}

.status-info {
    color: var(--info);
    background: var(--info-background);
}

.row-select {
    width: 100%;
    min-width: 160px;
    min-height: 32px;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
}

.row-select:focus {
    border-color: var(--primary);
    outline: 2px solid rgba(37, 99, 168, 0.15);
}

.row-select:disabled {
    opacity: 0.6;
}

.muted {
    color: #98a2b3;
}

/* ------------------------------------------------------------
   Dashboard timeline charts (hand-drawn canvas - no chart library)
------------------------------------------------------------ */

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    margin-bottom: 12px;
}

.chart-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0;
    border: none;
    background: none;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    user-select: none;
}

.chart-legend-item.disabled {
    color: var(--text-muted);
    opacity: 0.55;
}

.chart-legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    flex: none;
}

.chart-container {
    margin-top: 1em;
    position: relative;
    width: 100%;
}

/* Scale with the viewport (not a fixed pixel height) so the charts actually fill available
   window space on a large display, with floors/ceilings so they stay sane on very short or
   very tall windows. */
.chart-container-primary {
    height: clamp(360px, 55vh, 720px);
}

.chart-container-secondary {
    height: clamp(200px, 28vh, 400px);
}

.chart-container canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.chart-tooltip {
    position: absolute;
    z-index: 10;
    top: 0;
    left: 0;
    pointer-events: none;
    padding: 6px 10px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--text);
    white-space: nowrap;
    transform: translate(-50%, calc(-100% - 10px));
}

/* Member Details page's 7/30/90/365-day/All range select - sits inside .tab-list itself (not one
   tab's own panel), pushed to the far right via the flexbox auto-margin trick so it reads as
   governing every tab at once (Overview's chart/heatmap window, the gains tables, and the
   Competitions/Events date filter) rather than belonging to any single one. */
.tab-list-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    padding-bottom: 8px;
}

.range-select {
    min-height: 34px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
}

.button-small {
    min-height: 30px;
    padding: 4px 10px;
    font-size: 0.85rem;
}

.row-actions {
    display: flex;
    gap: 6px;
    white-space: nowrap;
}

.discord-edit {
    display: flex;
    align-items: center;
    gap: 6px;
}

.discord-id-input {
    flex: 1;
    min-width: 0;
}

/* Square, icon-only variant of .button - the icon keeps its usual right margin (see ".button i")
   for a button with trailing text, which needs cancelling out when there's no text after it. */
.button-icon-only {
    flex: none;
    width: 30px;
    padding: 0;
}

.button-icon-only i {
    margin-right: 0;
}

/* .button/.button-secondary has no disabled styling of its own (its background/border/color are
   all explicit, so the browser's native disabled look does nothing) - needed here so the Discord
   Save button visibly communicates "nothing to save" while its enable-on-change wiring keeps it
   disabled, same convention as .icon-button:disabled. */
.button-icon-only:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.review-thumb-btn {
    display: block;
    position: relative;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
}

.review-thumb {
    display: block;
    width: 64px;
    height: 64px;
    border: 1px solid var(--border);
    border-radius: 4px;
    object-fit: cover;
    background: var(--surface-muted);
}

/* Shown on the thumbnail when this row's evidence has more than one image (a single required
   item that needed several screenshots) - hints there's a gallery to open. */
.review-thumb-count {
    position: absolute;
    right: -6px;
    bottom: -6px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 11px;
    font-weight: 600;
}

.review-thumb-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 1.25rem;
}

.review-tile-warning {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--warning);
}

.dialog-backdrop {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: grid;
    place-items: center;
    background: rgba(15, 23, 42, 0.5);
}

.dialog-window {
    width: min(520px, calc(100vw - 32px));
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.35);
    color: var(--text);
}

.dialog-window.dialog-wide {
    width: min(720px, calc(100vw - 32px));
}

.dialog-image {
    display: block;
    max-width: 100%;
    max-height: 60vh;
    margin: 0 auto;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.dialog-caption {
    margin-top: 12px;
    color: var(--text-muted);
    white-space: pre-wrap;
    word-break: break-word;
}

/* Evidence gallery pop-up (showEvidenceGalleryDialog) - prev/next either side of the image,
   hidden entirely by the caller when there's only one image so a plain row looks unchanged. */
.evidenceGallery {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.evidenceGalleryNav {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface-muted);
    color: var(--text);
    font-size: 16px;
    cursor: pointer;
}

.evidenceGalleryNav:hover {
    background: var(--border);
}

.evidenceGalleryNav:disabled {
    opacity: 0.35;
    cursor: default;
}

.evidenceGalleryCounter {
    margin-top: 10px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.dialog-header,
.dialog-body,
.dialog-actions {
    padding: 16px;
}

.dialog-header {
    align-items: center;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 10px;
}

.dialog-header h2 {
    margin: 0;
    font-size: 1.1rem;
}

.dialog-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.dialog-body p {
    margin: 0;
}

.dialog-detail {
    margin-top: 12px;
    max-height: min(40vh, 300px);
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.85rem;
    color: var(--text-muted);
    background: var(--surface-muted);
    border-radius: 4px;
    padding: 10px;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding-top: 0;
}

.btn {
    display: inline-flex;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-weight: 600;
    line-height: 1;
}

.btn:hover {
    background: var(--surface-muted);
}

.btn.primary {
    color: #ffffff;
    background: var(--primary);
    border-color: transparent;
}

.btn.primary:hover {
    background: var(--primary-hover);
}

.btn.danger {
    color: #ffffff;
    background: var(--danger);
    border-color: transparent;
}

.btn.danger:hover {
    background: var(--danger-hover);
}

.empty-state {
    padding: 2rem;
    color: var(--text-muted);
    text-align: center;
    background: var(--surface-muted);
    border-radius: 0.375rem;
}

.tab-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.tab-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.tab-label {
    padding: 10px 16px;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
}

.tab-label:hover {
    color: var(--text);
}

.tab-count {
    margin-left: 4px;
    color: var(--text-muted);
    font-weight: 600;
}

.tab-panel {
    display: none;
}

/* JS-driven variant of the tab-list/tab-label/tab-panel classes above - the rules above this
   comment are wired to specific hidden-radio-input ids (Devices/Details.cshtml's checked-sibling
   CSS trick) and don't generalise. These two rules are id-agnostic: any page can toggle a plain
   ".active" class from JS instead (see wwwroot/js/competition/competition-details.js). */
.tab-label.active {
    border-bottom-color: var(--primary);
    color: var(--primary);
}

.tab-panel.active {
    display: block;
}

/* `.tab-label` alone has no background/border reset, since the Devices page always applies it
   to a <label>, not a real button. Scoped to real <button> elements only, so the pre-existing
   <label> usage is untouched. */
button.tab-label {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font: inherit;
}

/* ============================================================
   Reusable Markdown editor (wwwroot/js/core/markdownEditor.js)
   ============================================================ */

.markdown-editor {
    display: grid;
    gap: 8px;
}

/* The mode buttons (left) and whatever page-specific actions a caller moves into
   .markdown-editor-modebar-actions (right) - e.g. competition-details.js reparents its existing
   "Generate Draft"/Save/"View on Discord"/saved-at elements into writeupEditor.actionsSlot once
   the editor mounts, rather than leaving them in the surrounding page chrome. */
.markdown-editor-modebar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.markdown-editor-modebar-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.markdown-editor-modebar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
}

/* Tracks the write-up's length against Discord's 2000-character message limit (see
   DISCORD_MESSAGE_LIMIT in markdownEditor.js) - muted by default, .warn/.over escalate the colour
   as that limit is approached/passed. Purely a heads-up; nothing is blocked at either threshold. */
.markdown-editor-charcount {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.markdown-editor-charcount.warn {
    color: var(--warning);
}

.markdown-editor-charcount.over {
    color: var(--danger);
    font-weight: 600;
}

/* Compact, muted buttons for the editor's own toolbar row - deliberately smaller and
   lower-contrast than the page's regular .button/.button-primary/.button-secondary, which are
   sized for standalone page actions rather than a dense toolbar. .markdown-editor-toolbar-btn-
   accent (below) is kept in reserve for the one state that should actually stand out: an unsaved
   Save button - see setWriteupDirty() in competition-details.js. */
.markdown-editor-toolbar-btn {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 4px 8px;
    color: var(--text-muted);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 500;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
}

.markdown-editor-toolbar-btn i {
    margin-right: 0.3rem;
}

.markdown-editor-toolbar-btn:hover:not(:disabled) {
    color: var(--text);
    background: var(--surface-muted);
}

.markdown-editor-toolbar-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.markdown-editor-toolbar-btn.active {
    color: var(--primary);
    background: var(--surface-muted);
    border-color: var(--border);
}

.markdown-editor-toolbar-btn-accent {
    color: #ffffff;
    background: var(--primary);
    border-color: var(--primary);
}

.markdown-editor-toolbar-btn-accent:hover:not(:disabled) {
    color: #ffffff;
    background: var(--primary-hover);
}

.markdown-editor-wysiwyg-pane,
.markdown-editor-preview-pane {
    min-height: 400px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
}

/* Crepe's "frame" theme pads its ProseMirror editing surface generously (60px/120px) to read
   like a standalone document page - sensible for a full-page editor, way too much whitespace
   around the text once it's embedded in a form field alongside the source/preview panes (which
   use 12px, see below). Scoped to this component rather than touching the vendored theme CSS
   itself. Needs the extra ".markdown-editor" ancestor qualifier for specificity, not just style
   order: the vendored ".milkdown .ProseMirror" rule (milkdown-common.css) is two classes deep,
   same as a plain ".markdown-editor-wysiwyg-pane .ProseMirror" here, and it loads *after*
   clanforge.css (see the Styles section in Details.cshtml) - at equal specificity the later
   stylesheet wins regardless of which file the reader expects to take precedence, so this needs
   to genuinely outrank it, not just come later. */
.markdown-editor .markdown-editor-wysiwyg-pane .ProseMirror {
    padding: 16px;
}

/* Same specificity gotcha as the ProseMirror padding fix above: this textarea also matches the
   generic ".form-field textarea" rule (a class + a type selector, (0,1,1)) since it sits inside a
   .form-field - which otherwise beats a plain ".markdown-editor-textarea" ((0,1,0)) regardless of
   source order, shrinking it down to that rule's 38px min-height/8px padding/4px border-radius (a
   "couple of lines" tall) instead of these. The ".markdown-editor" ancestor qualifier pushes this
   to (0,2,0), which wins on class-count alone - border/background/border-radius are folded in
   here too rather than left to the shared pane rule above, for the same reason. */
.markdown-editor .markdown-editor-textarea {
    width: 100%;
    min-height: 400px;
    padding: 12px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
    resize: vertical;
}

.markdown-editor .markdown-editor-textarea:focus {
    border-color: var(--primary);
    outline: 2px solid rgba(37, 99, 168, 0.15);
}

.markdown-editor-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Same gotcha as .form-field[hidden] above: .markdown-editor-split's own "display: grid" is an
   author-stylesheet rule, so it beats the browser's default "[hidden] { display: none }" UA rule
   at equal specificity regardless of source order - without this, toggling .hidden on the split
   wrapper from JS does nothing and it stays visibly on screen in Editor/Markdown mode. */
.markdown-editor-split[hidden] {
    display: none;
}

.markdown-editor-preview-pane {
    padding: 12px;
    overflow-y: auto;
    color: var(--text);
}

/* Crepe's own vendored theme CSS (~/lib/milkdown/milkdown-frame.css) is a flat, light-only set of
   "--crepe-*" custom properties with no dark-mode variant of its own wired in - these overrides
   are ClanForge's side of that integration, mirroring the exact light/dark selector pattern used
   for ClanForge's own --surface/--text/etc. variables at the top of this file (system-preference
   default, explicit [data-theme] override in both directions). Values match Crepe's own
   "frame-dark" theme (@milkdown/crepe/lib/theme/frame-dark/style.css) - swapped in here instead
   of shipping a second vendored CSS file, since only the variables need to change per theme, not
   the structural rules that reference them. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .milkdown {
        --crepe-color-background: #1a1a1a;
        --crepe-color-on-background: #e6e6e6;
        --crepe-color-surface: #121212;
        --crepe-color-surface-low: #1c1c1c;
        --crepe-color-on-surface: #d1d1d1;
        --crepe-color-on-surface-variant: #a9a9a9;
        --crepe-color-outline: #757575;
        --crepe-color-primary: #b5b5b5;
        --crepe-color-secondary: #4d4d4d;
        --crepe-color-on-secondary: #d6d6d6;
        --crepe-color-inverse: #e5e5e5;
        --crepe-color-on-inverse: #2a2a2a;
        --crepe-color-inline-code: #ff6666;
        --crepe-color-error: #ff6666;
        --crepe-color-hover: #232323;
        --crepe-color-selected: #2f2f2f;
        --crepe-color-inline-area: #2b2b2b;
    }
}

:root[data-theme="dark"] .milkdown {
    --crepe-color-background: #1a1a1a;
    --crepe-color-on-background: #e6e6e6;
    --crepe-color-surface: #121212;
    --crepe-color-surface-low: #1c1c1c;
    --crepe-color-on-surface: #d1d1d1;
    --crepe-color-on-surface-variant: #a9a9a9;
    --crepe-color-outline: #757575;
    --crepe-color-primary: #b5b5b5;
    --crepe-color-secondary: #4d4d4d;
    --crepe-color-on-secondary: #d6d6d6;
    --crepe-color-inverse: #e5e5e5;
    --crepe-color-on-inverse: #2a2a2a;
    --crepe-color-inline-code: #ff6666;
    --crepe-color-error: #ff6666;
    --crepe-color-hover: #232323;
    --crepe-color-selected: #2f2f2f;
    --crepe-color-inline-area: #2b2b2b;
}

/* The split/source panes are ClanForge's own chrome, not Crepe's - themed with ClanForge's own
   --surface/--text/--border tokens already (see the rule above), so they follow dark mode
   automatically with no separate override needed here. */

#tab-software:checked ~ .tab-list label[for="tab-software"],
#tab-hardware:checked ~ .tab-list label[for="tab-hardware"],
#tab-groups:checked ~ .tab-list label[for="tab-groups"],
#tab-updates:checked ~ .tab-list label[for="tab-updates"] {
    border-bottom-color: var(--primary);
    color: var(--primary);
}

#tab-software:checked ~ #panel-software,
#tab-hardware:checked ~ #panel-hardware,
#tab-groups:checked ~ #panel-groups,
#tab-updates:checked ~ #panel-updates {
    display: block;
}

@media (max-width: 900px) {
    .app-body {
        display: block;
    }

    .topbar {
        flex-wrap: wrap;
        height: auto;
        padding: 10px 14px;
    }

    .topbar-clan {
        flex-wrap: wrap;
    }

    .topbar-input {
        width: 160px;
    }

    .sidebar {
        padding: 14px;
    }

    .sidebar-nav {
        display: flex;
        overflow-x: auto;
    }

    .main-content {
        padding: 20px 14px;
    }

    .filter-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .form-field {
        min-width: 0;
    }

    .filter-bar-summary {
        flex-basis: auto;
    }

    .pagination-bar {
        justify-content: space-between;
    }
}