/* Admin Platform Statistics dashboard.
   Namespaced with .ps- to avoid collisions; loaded globally via App.razor.

   Design intent: clear hierarchy (featured hero cards, then charts, then a quiet metric grid),
   calm surfaces (hairline border + soft shadow), and color reserved for meaning (trend up/down). */

/* ---- Section header (labeled divider) ---- */
.ps-section {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 28px 0 12px;
}

.ps-section:first-of-type {
    margin-top: 8px;
}

.ps-section__dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    flex: 0 0 auto;
}

.ps-section__dot--neutral {
    background: var(--mud-palette-text-secondary);
    opacity: 0.45;
}

.ps-section__title {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--mud-palette-text-secondary);
    white-space: nowrap;
}

.ps-section__rule {
    height: 1px;
    flex: 1 1 auto;
    background: var(--mud-palette-lines-default);
}

/* ---- Shared surface: cards (hero + chart panels) ---- */
.ps-card {
    height: 100%;
    box-sizing: border-box;
    padding: 16px 18px;
    border-radius: 16px;
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
}

.ps-card__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
}

.ps-card__title {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.3;
    color: var(--mud-palette-text-primary);
}

.ps-card__sub {
    font-size: 0.78rem;
    line-height: 1.3;
    color: var(--mud-palette-text-secondary);
    margin-top: 2px;
}

/* ---- Featured hero card ---- */
.ps-hero {
    display: flex;
    flex-direction: column;
    min-height: 188px;
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.ps-hero:hover {
    border-color: var(--mud-palette-lines-inputs);
    box-shadow: 0 4px 14px rgba(16, 24, 40, 0.10);
}

.ps-hero__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ps-hero__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: 11px;
    color: var(--mud-palette-tertiary);
    background: var(--mud-palette-action-default-hover); /* fallback if color-mix unsupported */
    background: color-mix(in srgb, var(--mud-palette-tertiary) 12%, transparent);
}

.ps-hero__eyebrow {
    margin-top: 12px;
    font-size: 0.66rem;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--mud-palette-text-secondary);
}

.ps-hero__value {
    font-size: 2.1rem;
    font-weight: 700;
    line-height: 1.05;
    margin-top: 2px;
    color: var(--mud-palette-text-primary);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
}

.ps-hero__label {
    font-size: 0.82rem;
    line-height: 1.2;
    margin-top: 2px;
    color: var(--mud-palette-text-secondary);
}

.ps-hero__spark {
    margin-top: auto;
    padding-top: 12px;
}

.ps-hero__foot {
    font-size: 0.72rem;
    line-height: 1.2;
    margin-top: 6px;
    color: var(--mud-palette-text-secondary);
    min-height: 0.9rem;
}

/* ---- Inline SVG sparkline ---- */
.ps-spark {
    position: relative;
    width: 100%;
    display: block;
}

.ps-spark__svg {
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
}

.ps-spark__line {
    fill: none;
    stroke: currentColor;
    stroke-width: 2px;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.ps-spark__area {
    stroke: none;
    fill: currentColor;
    opacity: 0.14;
}

.ps-spark__dot {
    position: absolute;
    right: 0;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
    transform: translate(0, -50%);
    box-shadow: 0 0 0 2px var(--mud-palette-surface);
}

/* ---- Secondary KPI tile (calmer: neutral surface, color only on the trend pill) ---- */
.ps-tile {
    height: 100%;
    min-height: 96px;
    box-sizing: border-box;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 14px 16px;
    border-radius: 14px;
    background: var(--mud-palette-surface);
    border: 1px solid var(--mud-palette-lines-default);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.03);
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.ps-tile:hover {
    border-color: var(--mud-palette-lines-inputs);
    box-shadow: 0 3px 10px rgba(16, 24, 40, 0.07);
}

.ps-tile__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 32px;
}

.ps-tile__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    border-radius: 9px;
    color: var(--mud-palette-text-secondary);
    background: var(--mud-palette-action-default-hover);
}

.ps-tile__value {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.05;
    color: var(--mud-palette-text-primary);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.01em;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ps-tile__label {
    font-size: 0.78rem;
    line-height: 1.2;
    color: var(--mud-palette-text-secondary);
}

/* ---- Trend pill (color = meaning) ---- */
.ps-trend {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    white-space: nowrap;
}

.ps-trend__arrow {
    font-size: 0.6rem;
    line-height: 1;
}

.ps-trend--up {
    color: var(--mud-palette-success);
    background: var(--mud-palette-action-default-hover); /* fallback */
    background: color-mix(in srgb, var(--mud-palette-success) 14%, transparent);
}

.ps-trend--down {
    color: var(--mud-palette-error);
    background: var(--mud-palette-action-default-hover); /* fallback */
    background: color-mix(in srgb, var(--mud-palette-error) 14%, transparent);
}

.ps-trend--flat {
    color: var(--mud-palette-text-secondary);
    background: var(--mud-palette-action-default-hover);
}

.ps-trend--all {
    color: var(--mud-palette-text-disabled);
    background: var(--mud-palette-action-default-hover);
    font-weight: 500;
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
    .ps-section {
        margin: 22px 0 10px;
    }

    .ps-hero {
        min-height: 0;
    }

    .ps-hero__value {
        font-size: 1.85rem;
    }

    .ps-tile {
        min-height: 84px;
        padding: 12px 13px;
    }

    .ps-tile__value {
        font-size: 1.4rem;
    }
}

/* ==== Engagement page (/admin/statistics/engagement) ====
   Reuses the .ps- surfaces above so the two pages read as one family. Its own pieces are prefixed
   .eng- and use MudBlazor theme tokens only, so dark mode needs nothing extra. */

/* A real heading for each block, styled exactly like the platform page's section label. */
h2.ps-section__title {
    margin: 0;
    line-height: inherit;
}

/* Each block is its own <section>, so every header is a :first-of-type and would lose the gap above
   it. Restore the gap between blocks and keep the tight one only for the first block. */
.eng-page section > .ps-section {
    margin-top: 28px;
}

.eng-page > section:first-of-type > .ps-section {
    margin-top: 8px;
}

/* Share-of-members pill on the active cards (neutral: a share is not a trend). */
.eng-pill {
    display: inline-flex;
    align-items: center;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    white-space: nowrap;
    color: var(--mud-palette-text-secondary);
    background: var(--mud-palette-action-default-hover);
    font-variant-numeric: tabular-nums;
}

/* Thin meter under an active count: how much of the membership it is. Sits at the card's foot like
   the platform cards' sparkline. */
.eng-meter {
    margin-top: auto;
    padding-top: 12px;
}

.eng-meter__track,
.eng-barlist__track,
.eng-share-bar__track {
    display: block;
    height: 6px;
    border-radius: 999px;
    overflow: hidden;
    background: var(--mud-palette-action-default-hover);
}

.eng-meter__fill,
.eng-barlist__fill,
.eng-share-bar__fill {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: var(--mud-palette-primary);
}

/* One line of help under a block. */
.eng-help {
    margin: 10px 2px 0;
    font-size: 0.78rem;
    line-height: 1.35;
    color: var(--mud-palette-text-secondary);
}

/* ---- Daily column chart ---- */
.eng-bars {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-rows: 160px auto;
    column-gap: 8px;
    row-gap: 6px;
}

.eng-bars__empty {
    grid-column: 1 / -1;
    grid-row: 1 / -1;
    font-size: 0.85rem;
    color: var(--mud-palette-text-secondary);
}

.eng-bars__scale {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    font-size: 0.7rem;
    color: var(--mud-palette-text-secondary);
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.eng-bars__plot {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    min-width: 0;
    overflow: hidden;
    border-bottom: 1px solid var(--mud-palette-lines-default);
    background-image: linear-gradient(var(--mud-palette-lines-default) 1px, transparent 1px);
    background-size: 100% 50%;
}

.eng-bars__col {
    flex: 1 1 0;
    min-width: 0;
    height: 100%;
    display: flex;
    align-items: flex-end;
}

.eng-bars__bar {
    display: block;
    width: 100%;
    min-height: 2px;
    border-radius: 3px 3px 0 0;
    background: var(--mud-palette-primary);
    opacity: 0.85;
}

.eng-bars__bar--zero {
    background: var(--mud-palette-lines-default);
    opacity: 1;
}

/* A long range (more than about two months of columns): the gaps alone would be wider than the plot,
   so the columns touch. Two classes, so the phone rule's gap cannot win. */
.eng-bars__plot.eng-bars__plot--dense {
    gap: 0;
}

.eng-bars__plot.eng-bars__plot--dense .eng-bars__bar {
    border-radius: 0;
}

/* A day before counting began: faint hatching across the full height, never a bar that reads as 0. */
.eng-bars__col--uncounted {
    align-self: stretch;
    background: repeating-linear-gradient(135deg,
        transparent 0, transparent 3px,
        var(--mud-palette-lines-default) 3px, var(--mud-palette-lines-default) 4px);
    opacity: 0.7;
}

/* The share line under a contributor tile (Only read). */
.eng-tile__share {
    font-size: 0.72rem;
    line-height: 1.2;
    color: var(--mud-palette-text-secondary);
    font-variant-numeric: tabular-nums;
}

@media (hover: hover) and (pointer: fine) {
    .eng-bars__col:hover .eng-bars__bar {
        opacity: 1;
    }
}

.eng-bars__axis {
    grid-column: 2;
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 0.7rem;
    color: var(--mud-palette-text-secondary);
    white-space: nowrap;
}

/* ---- Bar list (time bands) ---- */
.eng-barlist {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.eng-barlist__row {
    display: grid;
    grid-template-columns: minmax(110px, 9rem) 1fr minmax(4.5rem, auto);
    align-items: center;
    gap: 10px;
    font-size: 0.82rem;
}

.eng-barlist__label {
    color: var(--mud-palette-text-primary);
}

/* The bars in the lists are a touch thicker than the card meters, coloured like their block's dot. */
.eng-barlist__track,
.eng-share-bar__track {
    height: 8px;
}

.eng-barlist__fill {
    background: var(--mud-palette-success);
}

.eng-share-bar__fill {
    background: var(--mud-palette-tertiary);
}

/* The band's share of all member days, with the count of member days quietly beneath it. */
.eng-barlist__value {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.eng-barlist__share {
    font-weight: 600;
    color: var(--mud-palette-text-primary);
}

.eng-barlist__count {
    font-size: 0.7rem;
    color: var(--mud-palette-text-secondary);
    white-space: nowrap;
}

/* ---- Sections table ---- */
.eng-table-card {
    padding: 4px 6px;
}

.eng-table-card .mud-table,
.eng-table-card .mud-simple-table {
    background: transparent;
}

/* A narrow screen scrolls the table inside its card instead of widening the page. */
.eng-table-card .mud-table-container {
    overflow-x: auto;
}

/* Two classes: MudBlazor's own header rule (".mud-simple-table table * tr th") has one and would win. */
.eng-table.mud-simple-table th {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--mud-palette-text-secondary);
    white-space: nowrap;
}

.eng-table .eng-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.eng-table .eng-share-col {
    width: 34%;
    min-width: 140px;
}

.eng-share-bar {
    display: grid;
    grid-template-columns: 1fr 3.5rem;
    align-items: center;
    gap: 10px;
}

.eng-share-bar__value {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.eng-empty {
    padding: 18px 12px;
    font-size: 0.88rem;
    color: var(--mud-palette-text-secondary);
}

/* The privacy floor: time and sections are withheld when too few members were active to stay anonymous. */
.eng-withheld {
    padding: 18px 12px;
    font-size: 0.88rem;
    line-height: 1.4;
    color: var(--mud-palette-text-secondary);
}

.ps-card.eng-withheld {
    padding: 18px;
}

@media (max-width: 600px) {
    .eng-bars {
        grid-template-rows: 120px auto;
    }

    .eng-bars__plot {
        gap: 1px;
    }

    .eng-barlist__row {
        grid-template-columns: minmax(90px, 7.5rem) 1fr minmax(4rem, auto);
        gap: 8px;
    }

    .eng-page section > .ps-section {
        margin-top: 22px;
    }

    .eng-page > section:first-of-type > .ps-section {
        margin-top: 8px;
    }

    /* The sections table fits a phone: tighter cells (beating MudBlazor's dense padding), headers that
       wrap, no Views column and the share as a number without its bar. */
    .eng-table.mud-simple-table.mud-table-dense th,
    .eng-table.mud-simple-table.mud-table-dense td {
        padding: 6px 8px;
    }

    .eng-table.mud-simple-table th {
        white-space: normal;
    }

    .eng-table.mud-simple-table .eng-col-views {
        display: none;
    }

    .eng-table .eng-share-bar__track {
        display: none;
    }

    .eng-table .eng-share-col {
        width: auto;
        min-width: 0;
    }

    .eng-share-bar {
        grid-template-columns: auto;
        justify-items: end;
    }
}

/* ==== Member activity (/admin/statistics/engagement/members) and a member's Activity tab ====
   Administrators only. The same family as the Engagement page: .eng- pieces on the .ps- surfaces, theme
   tokens only, so dark mode needs nothing extra. */

/* Filter chips: one selected at a time. They wrap on a phone, never a sideways strip that eats taps. */
.eng-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.eng-chip {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 6px 14px;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 999px;
    background: var(--mud-palette-surface);
    color: var(--mud-palette-text-primary);
    font: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    touch-action: manipulation;
}

.eng-chip[aria-pressed="true"] {
    border-color: var(--mud-palette-primary);
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
}

.eng-chip:focus-visible,
.eng-sort:focus-visible,
.eng-members__name a:focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: 2px;
}

.eng-members__search {
    max-width: 360px;
    margin-top: 12px;
}

.eng-members__count {
    margin: 16px 2px 8px;
    font-size: 0.85rem;
    color: var(--mud-palette-text-secondary);
    font-variant-numeric: tabular-nums;
}

/* While a change loads, the list on screen dims (and says it is busy) until the new one arrives. */
.eng-members__table--busy {
    opacity: 0.6;
    transition: opacity 0.15s ease-in;
}

/* A sortable header is one real button; the arrow shows on the sorted column only. It keeps the header's
   own small capitals. */
.eng-sort {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    text-align: inherit;
    cursor: pointer;
    touch-action: manipulation;
}

.eng-sort--active {
    color: var(--mud-palette-text-primary);
}

.eng-sort__arrow {
    font-size: 0.6rem;
}

/* The name cell is the row's header (<th scope="row">), but it must read like the other cells, not like
   the small capitals of the column headers. More specific than ".eng-table.mud-simple-table th". */
.eng-members-table.mud-simple-table tbody th {
    font-size: inherit;
    font-weight: 400;
    letter-spacing: normal;
    text-transform: none;
    white-space: normal;
    color: var(--mud-palette-text-primary);
}

/* The member's name links to their Activity tab; a long name wraps instead of widening the table. The
   name is in the text colour and the link is the primary underline: primary text alone was 4.37:1 on the
   dark surface. */
.eng-members__name {
    overflow-wrap: anywhere;
}

.eng-members__name a {
    color: var(--mud-palette-text-primary);
    font-weight: 600;
    text-decoration: underline;
    text-decoration-color: var(--mud-palette-primary);
    text-decoration-thickness: 2px;
    text-underline-offset: 3px;
}

.eng-pill.eng-pill--staff {
    margin-left: 2px;
    color: var(--mud-palette-text-primary);
    border: 1px solid var(--mud-palette-lines-default);
    background: transparent;
}

.eng-members__day {
    white-space: nowrap;
}

/* What the last seen day is based on, quietly beneath it. */
.eng-members__kind {
    display: block;
    font-size: 0.72rem;
    line-height: 1.3;
    color: var(--mud-palette-text-secondary);
}

.eng-members__pager {
    display: flex;
    justify-content: center;
    margin-top: 16px;
}

@media (hover: hover) and (pointer: fine) {
    .eng-chip:hover {
        background: var(--mud-palette-action-default-hover);
    }

    .eng-chip[aria-pressed="true"]:hover {
        background: var(--mud-palette-primary-darken);
    }

    .eng-sort:hover {
        color: var(--mud-palette-text-primary);
    }

    .eng-members__name a:hover {
        text-decoration-thickness: 3px;
    }
}

/* A member's Activity tab: the range and the quick ranges above the tiles. */
.eng-member__bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.eng-member__range {
    font-size: 0.8rem;
    color: var(--mud-palette-text-secondary);
}

/* The progress bar's slot is always there, so a range change never pushes the activity down. */
.eng-member__progress {
    height: 4px;
    margin-bottom: 8px;
    overflow: hidden;
}

/* A day or a phrase in a tile is smaller than a number, and wraps instead of being cut ("Not seen since
   Sep 1, 2026"). Two classes, so the phone rule cannot win. */
.ps-tile__value.eng-tile__value--text {
    font-size: 1.1rem;
    line-height: 1.2;
    white-space: normal;
    overflow-wrap: anywhere;
    text-overflow: clip;
}

.eng-member__note {
    margin-top: 20px;
}

/* Below the width all nine columns need (a tablet, or a laptop with the menu open) the Members table drops
   its four counts, which a member's own tab shows. Otherwise it scrolls sideways inside its card, and a
   sideways strip swallows taps on the name links. */
@media (max-width: 1279.98px) {
    .eng-members-table.mud-simple-table .eng-col-count {
        display: none;
    }
}

/* On a phone the Members table also drops Joined: the member, last seen, active days and time stay. The
   cells tighten, the headers and the last seen day wrap (a duration only breaks between hours and minutes),
   so 360 px fits and the page never scrolls sideways. */
@media (max-width: 768px) {
    .eng-members-table.mud-simple-table .eng-col-joined {
        display: none;
    }

    .eng-members-table.mud-simple-table.mud-table-dense th,
    .eng-members-table.mud-simple-table.mud-table-dense td {
        padding: 6px 8px;
    }

    .eng-members-table.mud-simple-table th {
        white-space: normal;
    }

    .eng-members-table .eng-members__day {
        white-space: normal;
    }

    .eng-members__search {
        max-width: none;
    }
}

/* On a touch screen every control is at least 44 px tall. The name link grows by padding that a negative
   margin gives back, so a row looks the same as with a mouse. */
@media (pointer: coarse) {
    .eng-chip {
        min-height: 44px;
    }

    .eng-sort {
        min-height: 44px;
    }

    .eng-members__pager button {
        min-width: 44px;
        min-height: 44px;
    }

    .eng-members__name a {
        display: inline-block;
        padding-block: 12px;
        margin-block: -12px;
    }
}
