﻿/* Plugin subscriptions, prices and usage by person (ADR-36…38): the Plugin subscriptions page, the plugin's
   Subscribers tab, the "By person" usage table and the user page cards. Global (not scoped) because the rules reach
   into MudBlazor components; every colour is a theme token of portal.css. */

/* --- Shared pieces ------------------------------------------------------------------------------------------- */
.ps-label {
    font-size: .76rem;
    font-weight: 600;
    color: var(--app-ink-muted);
    margin-bottom: 2px;
}

.ps-nowrap {
    white-space: nowrap;
}

.ps-clip {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* The people list grows with the page (the page scrolls), not a fixed-height box with empty space under it. */
.ps-table-wrap {
    max-height: none;
}

.ps-row-action {
    width: 1%;
    white-space: nowrap;
    text-align: right;
}

.ps-section-title {
    margin: 20px 0 8px;
    font-size: .95rem;
    font-weight: 600;
    color: var(--app-ink);
}

.ps-person {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 3px 0;
    line-height: 1.25;
}

.ps-person__name {
    font-weight: 600;
    color: var(--app-ink);
    overflow-wrap: anywhere;
}

.ps-person__email {
    font-size: .74rem;
    color: var(--app-ink-muted);
    overflow-wrap: anywhere;
}

.ps-person.is-deleted .ps-person__name {
    font-weight: 500;
    font-style: italic;
    color: var(--app-ink-muted);
}

.po-table tr.is-muted td {
    color: var(--app-ink-muted);
}

/* A plugin on a person: name, then its period as a small switch, then the cross. */
.ps-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 3px 0;
}

.ps-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    max-width: 260px;
    padding: 0 2px 0 8px;
    border: 1px solid var(--app-accent-border);
    border-radius: 11px;
    background: var(--app-surface);
    color: var(--app-accent);
    font-size: .76rem;
    font-weight: 600;
    line-height: 22px;
}

.ps-chip.is-fixed {
    padding-right: 3px;
    border-color: var(--app-line-strong);
    color: var(--app-ink);
}

.ps-chip__name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ps-chip__period {
    padding: 0 6px;
    border: 0;
    border-radius: 8px;
    background: var(--app-surface-alt);
    color: var(--app-ink-muted);
    font: inherit;
    font-size: .68rem;
    line-height: 16px;
    white-space: nowrap;
}

.ps-chip__period.is-annual {
    background: var(--app-accent-soft);
    color: var(--app-accent);
}

button.ps-chip__period {
    cursor: pointer;
}

button.ps-chip__period:hover:not(:disabled) {
    background: var(--app-accent-soft);
    color: var(--app-accent);
}

.ps-chip__remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--app-ink-muted);
    cursor: pointer;
}

.ps-chip__remove .mud-icon-root {
    font-size: .9rem;
}

.ps-chip__remove:hover:not(:disabled) {
    background: var(--app-surface-alt);
    color: var(--app-danger);
}

.ps-chip__period:focus-visible,
.ps-chip__remove:focus-visible,
.ps-col-check input:focus-visible {
    outline: var(--app-ring-width, 2px) solid var(--app-accent);
    outline-offset: 1px;
}

.ps-col-check {
    width: 32px;
    text-align: center;
}

.ps-col-check input {
    width: 16px;
    height: 16px;
    accent-color: var(--app-accent);
    cursor: pointer;
}

.po-table tbody tr.is-selected td {
    background: var(--app-accent-soft);
}

/* --- Add people / plugins: picker, billing period, button on one line ---------------------------------------- */
.ps-add {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
    margin-bottom: 4px;
}

.ps-add__picker {
    flex: 1 1 260px;
    min-width: 0;
}

.ps-add__period {
    flex: 0 0 auto;
}

/* --- Price and access card ------------------------------------------------------------------------------------ */
.ps-tab {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Price and access: the price on the left (three fields in a row and what they come to), who may use the plugin on
   the right behind a rule, Save and Undo at the foot. */
.ps-pricing__row {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 16px 28px;
}

.ps-pricing__price {
    flex: 2 1 520px;
    min-width: 0;
}

.ps-pricing__fields {
    display: grid;
    grid-template-columns: repeat(3, minmax(150px, 1fr));
    gap: 4px 16px;
    margin-top: 6px;
}

.ps-pricing__note {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    margin-top: 10px;
    padding: 8px 12px;
    border: 1px solid var(--app-accent-border);
    background: var(--app-accent-soft);
    color: var(--app-ink);
    font-size: .82rem;
    line-height: 1.4;
}

.ps-pricing__note .mud-icon-root {
    flex: none;
    margin-top: 1px;
    color: var(--app-accent);
}

.ps-pricing__mode {
    flex: 1 1 260px;
    padding-left: 28px;
    border-left: 1px solid var(--app-line);
}

.ps-pricing__mode .po-helper {
    margin-top: 8px;
}

.ps-pricing__actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
    align-items: center;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--app-line);
}

/* The price is the one figure of the card: set large in the figures face. */
.ps-figure {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin: 4px 0 2px;
}

.ps-figure__value {
    font-family: var(--app-font-figures, inherit);
    font-size: 1.6rem;
    font-weight: 600;
    line-height: 1.1;
    color: var(--app-ink);
    font-variant-numeric: tabular-nums;
}

.ps-figure__unit {
    font-size: .8rem;
    color: var(--app-ink-muted);
}

.ps-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.ps-find {
    margin-left: auto;
    max-width: 240px;
}

/* --- Plugin subscriptions page ---------------------------------------------------------------------------------- */
.ps-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    margin-bottom: 10px;
}

.ps-toolbar__search {
    flex: 1 1 260px;
    max-width: 360px;
}

.ps-toolbar__filter {
    flex: 0 1 220px;
}

.ps-bulk {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
    margin-bottom: 10px;
    padding: 8px 12px;
    border: 1px solid var(--app-accent-border);
    border-radius: 8px;
    background: var(--app-accent-soft);
}

.ps-bulk__count {
    font-weight: 600;
    color: var(--app-ink);
}

.ps-bulk__plugin {
    flex: 0 1 260px;
    background: var(--app-surface);
}

.ps-people-table td:nth-last-child(2),
.ps-people-table td:nth-last-child(3) {
    white-space: nowrap;
}

/* The list price before the discount (ADR-39). */
.ps-list-price {
    margin-right: 6px;
    font-size: .85em;
    color: var(--app-ink-muted);
}

/* A person's own discount edited in a row or a plugin chip (ADR-40). */
.ps-discount-edit {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.ps-discount-edit .mud-input-control {
    width: 104px;
    margin: 0;
}

.ps-everyone {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
}

.ps-everyone .ps-label {
    margin: 0 2px 0 0;
}

.ps-user-grid {
    align-items: start;
}

/* People picker items: name over email. */
.pp-person {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.pp-email {
    font-size: .74rem;
    color: var(--app-ink-muted);
}

@media (max-width: 600px) {
    .ps-pricing__fields {
        grid-template-columns: 1fr;
    }

    .ps-pricing__price,
    .ps-pricing__mode,
    .ps-toolbar__search,
    .ps-toolbar__filter,
    .ps-bulk__plugin {
        flex-basis: 100%;
        max-width: none;
    }

    .ps-find {
        max-width: none;
        width: 100%;
    }

    .ps-chip {
        max-width: 100%;
    }
}

/* The user page: the plugins card a little wider than the usage card. */
.po-grid.ps-user-grid {
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
}

@media (max-width: 1000px) {
    .po-grid.ps-user-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* Design review fixes: totals stay in sight while the rows scroll; the plugin filter keeps a sensible width. */
.ps-table-wrap .po-table tfoot td {
    position: sticky;
    bottom: 0;
    z-index: 1;
    border-top: 1px solid var(--app-line-strong);
}

.ps-toolbar__filter {
    max-width: 280px;
}

.ps-user-card .po-table td:first-child {
    min-width: 120px;
}

/* Phones: tables keep readable columns and scroll sideways inside their own box instead of squeezing names to a
   letter per line. */
@media (max-width: 760px) {
    .ps-people-table {
        min-width: 640px;
    }

    .ps-people-table td:nth-child(2) {
        min-width: 180px;
    }

    .ps-prices-table,
    .ps-by-person .po-table,
    .ps-tab .po-table {
        min-width: 620px;
    }

    .ps-user-card .po-table {
        min-width: 480px;
    }

    .ps-toolbar__filter {
        max-width: none;
    }
}

/* Narrow: the access part drops under the price, so its rule runs along the top. */
@media (max-width: 1280px) {
    .ps-pricing__mode {
        flex-basis: 100%;
        padding: 14px 0 0;
        border-left: 0;
        border-top: 1px solid var(--app-line);
    }
}

/* The discount on a chip: applied (the plugin's or the person's own) reads in the accent, "no discount" stays quiet. */
.ps-chip__discount.is-applied {
    background: var(--app-accent-soft);
    color: var(--app-accent);
    font-weight: 600;
}

.ps-chip__discount.is-own {
    outline: 1px solid var(--app-accent-border);
}

/* The discount dialog: three choices as cards, the own one with presets, then what the person pays. */
.ps-dd__title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.ps-dd__sub {
    margin-top: 2px;
    font-size: .8rem;
    color: var(--app-ink-muted);
}

.ps-dd {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ps-dd__option {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--app-line);
    background: var(--app-surface);
    color: var(--app-ink);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.ps-dd__option:hover {
    border-color: var(--app-accent-border);
}

.ps-dd__option.is-on {
    border-color: var(--app-accent);
    background: var(--app-accent-soft);
}

.ps-dd__option:focus-visible {
    outline: var(--app-ring-width, 2px) solid var(--app-accent);
    outline-offset: 1px;
}

.ps-dd__radio {
    flex: none;
    width: 16px;
    height: 16px;
    margin-top: 2px;
    border: 2px solid var(--app-line-strong);
    border-radius: 50%;
}

.ps-dd__option.is-on .ps-dd__radio {
    border-color: var(--app-accent);
    box-shadow: inset 0 0 0 3px var(--app-surface), inset 0 0 0 8px var(--app-accent);
}

.ps-dd__text {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ps-dd__label {
    font-weight: 600;
}

.ps-dd__hint {
    font-size: .8rem;
    color: var(--app-ink-muted);
}

.ps-dd__own {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
}

.ps-dd__input {
    flex: 0 0 110px;
    margin: 0;
}

.ps-dd__preset {
    padding: 4px 10px;
    border: 1px solid var(--app-line);
    background: var(--app-surface);
    color: var(--app-ink);
    font: inherit;
    font-size: .8rem;
    cursor: pointer;
}

.ps-dd__preset:hover,
.ps-dd__preset.is-on {
    border-color: var(--app-accent);
    color: var(--app-accent);
}

.ps-dd__result {
    display: flex;
    gap: 24px;
    margin-top: 14px;
    padding: 10px 12px;
    border-top: 1px solid var(--app-line);
}

.ps-dd__result > div {
    display: flex;
    flex-direction: column;
}

.ps-dd__result-label {
    font-size: .74rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--app-ink-muted);
}

.ps-dd__result-value {
    font-family: var(--app-font-figures, inherit);
    font-size: 1.25rem;
    font-weight: 700;
}
