/*
 * The trade board (Trade\Board): the list, a listing, the form.
 * Loaded on the section's screens, an item's page in the base and the trading
 * tab of a profile.
 */

.trade-back {
    margin: 0 0 var(--space-s);
    font-size: var(--text-xs);
}

.trade-back__link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3xs);
    color: var(--color-text-muted);
}

/* The arrow icon points right; "back" points left. */
.trade-back__link .icon {
    transform: scaleX(-1);
}

.trade-empty {
    color: var(--color-text-muted);
    font-size: var(--text-s);
}

/* ============ Board: one panel, like a news entry beside the sidebar ============ */
.trade-board {
    display: grid;
    gap: var(--space-s);
    padding: var(--space-l) var(--space-xl);
    background: var(--color-surface);
    border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-l);
}

@media (max-width: 40rem) {
    .trade-board {
        padding: var(--space-m) var(--space-s);
    }
}

.trade-board__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-xs) var(--space-s);
    padding-bottom: var(--space-s);
    border-bottom: var(--border-thin) solid var(--color-border);
}

.trade-board__title {
    margin: 0;
    font-size: var(--text-3xl);
    letter-spacing: -0.01em;
}

/* The step an article's title takes on a phone (.article__title). */
@media (max-width: 40rem) {
    .trade-board__title {
        font-size: var(--text-xl);
    }
}

/*
 * The switch on a line of its own, the four fields in one row under it. As a
 * wrapping flex row they shared the first line with the switch and broke
 * wherever they ran out of room, leaving the rarity select and the button on
 * a second line of their own.
 */
.trade-board__bar {
    --trade-control: 2.5rem;

    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto auto auto;
    align-items: center;
    gap: var(--space-2xs);
}

.trade-board__tabs {
    grid-column: 1 / -1;
    justify-self: start;
}

.trade-board__bar input,
.trade-board__bar select,
.trade-board__bar .button {
    height: var(--trade-control);
    padding-block: 0;
}

/*
 * A segmented switch: the two lists are one control, not two buttons. Cut the
 * same way as the game switch of the knowledge base (`.db-games`) - the site
 * has one shape for "two positions of one choice", and the board had its own.
 */
.trade-board__tabs {
    display: inline-flex;
    align-self: center;
    flex-shrink: 0;
    border: var(--border-thin) solid var(--color-border-accent);
    border-radius: var(--radius-m);
    /* The fill of a selected half has to stop at the rounded corner. */
    overflow: hidden;
}

.trade-board__tab {
    display: inline-flex;
    align-items: center;
    /* The padding of `.db-games__link`, not a height borrowed from the fields
       beside it: the switch is sized by its own text, as it is in the base. */
    padding: var(--space-3xs) var(--space-s);
    color: var(--color-text-muted);
    font-family: var(--font-heading);
    font-size: var(--text-xs);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
    white-space: nowrap;
}

.trade-board__tab:hover,
.trade-board__tab:focus-visible {
    /* The halves are a control, not prose: an underline under one of them
       reads as a second selected state. */
    color: var(--color-heading);
    text-decoration: none;
}

.trade-board__tab--current,
.trade-board__tab--current:hover {
    background: var(--color-border-accent);
    color: var(--color-heading);
}

.trade-board__search {
    flex: 1 1 12rem;
    min-width: 0;
}

.trade-board__search input {
    width: 100%;
}

.trade-board__select {
    flex: 0 1 auto;
    min-width: 0;
}

.trade-board__select select {
    max-width: 11rem;
    font-size: var(--text-xs);
}

.trade-board__submit {
    flex-shrink: 0;
    width: var(--trade-control);
    padding-inline: 0;
    justify-content: center;
}

/*
 * The shape the knowledge base's toolbar takes at this width: the tabs across
 * the top, search and its button on the line under them, the selects two to a
 * line below. Left to wrap, the row broke into four ragged lines and left the
 * button alone on the last one. The search field is the first label, so the
 * selects are the even (left column) and odd (right) labels after it, and a
 * lone last select takes the whole line.
 */
@media (max-width: 40rem) {
    .trade-board__bar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
    }

    /* Centred over the fields, the way the game switch sits over the sections. */
    .trade-board__tabs {
        justify-self: center;
    }

    .trade-board__search {
        grid-column: 1 / 3;
    }

    .trade-board__submit {
        grid-column: 3;
        grid-row: 2;
    }

    .trade-board__select:nth-of-type(even) {
        grid-column: 1;
    }

    .trade-board__select:nth-of-type(odd) {
        grid-column: 2 / -1;
    }

    .trade-board__select:nth-of-type(even):last-of-type {
        grid-column: 1 / -1;
    }

    .trade-board__select select {
        width: 100%;
        max-width: none;
    }
}

.trade-board__count {
    margin: 0;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
}

.trade-board__rules {
    margin: var(--space-s) 0 0;
    padding-top: var(--space-s);
    border-top: var(--border-thin) solid var(--color-border);
    color: var(--color-text-muted);
    font-size: var(--text-xs);
}

/* Rows on a panel sit a step down from it, not on the same surface. */
.trade-board .trade-row,
.db-trades .trade-row {
    background: var(--color-surface-sunken);
}

/* ============ Board rows ============ */
.trade-list {
    display: grid;
    gap: var(--space-2xs);
    margin: 0;
    padding: 0;
    list-style: none;
}

/*
 * Two tiers, not three columns. A fixed column for the kind, a column for the
 * item and one for the meta left what is wanted about half the panel wide, and
 * every wanted item broke its name over two lines with its difficulty stranded
 * beside it - four narrow columns of text in a row 700px wide.
 */
.trade-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
        'head meta'
        'wants wants';
    gap: var(--space-2xs) var(--space-s);
    align-items: start;
    padding: var(--space-xs) var(--space-s);
    background: var(--color-surface);
    border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-m);
}

.trade-row:hover {
    border-color: var(--color-border-strong);
}

/*
 * In a member's list, a listing that is no longer open reads as history: dimmed,
 * the item's colour gone. The board's "deals" tab is all of them, so it is not dimmed.
 */
.profile-list .trade-row--done,
.profile-list .trade-row--closed,
.profile-list .trade-row--expired {
    opacity: 0.55;
    filter: grayscale(1);
}

@media (max-width: 40rem) {
    .trade-row {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            'head'
            'wants'
            'meta';
    }
}

.trade-row__kind {
    justify-self: start;
    padding: var(--space-3xs) var(--space-2xs);
    border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-s);
    font-family: var(--font-heading);
    font-size: var(--text-2xs);
    letter-spacing: var(--tracking-wider);
    text-transform: uppercase;
    color: var(--color-text-strong);
}

.trade-row__kind--give {
    border-color: var(--color-success);
    color: var(--color-success);
}

.trade-row__kind--swap {
    border-color: var(--color-border-accent);
    color: var(--color-accent);
}

.trade-row__kind--seek {
    border-color: var(--color-info);
    color: var(--color-info);
}

/* The kind and the item are one line: the badge says what the line means. */
.trade-row__head {
    grid-area: head;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2xs) var(--space-s);
    min-width: 0;
}

.trade-row__wants {
    grid-area: wants;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3xs) var(--space-xs);
    margin: 0;
    font-size: var(--text-xs);
}

.trade-row__wants-label {
    color: var(--color-text-muted);
}

/* The line wraps between items, not inside one: a name broken in half with its
   difficulty beside it was what made the list read as columns. */
.trade-row__wants .trade-item {
    flex-wrap: nowrap;
    white-space: nowrap;
}

/* On a phone a name longer than the line is cut rather than let out of the
   panel - `nowrap` takes away the break that used to save it. */
.trade-row__wants .trade-item__name {
    overflow: hidden;
    text-overflow: ellipsis;
}

.trade-row__wants-text {
    color: var(--color-text);
}

.trade-row__meta {
    grid-area: meta;
    display: grid;
    justify-items: end;
    gap: var(--space-3xs);
    font-size: var(--text-xs);
    color: var(--color-text-muted);
    text-align: end;
}

@media (max-width: 40rem) {
    .trade-row__meta {
        justify-items: start;
        text-align: start;
    }
}

.trade-row__author {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3xs);
}

.trade-row__author-link {
    color: var(--color-text-strong);
}

.trade-row__facts {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs);
}

.trade-row__badge {
    padding: 0 var(--space-3xs);
    border: var(--border-thin) solid var(--color-danger);
    border-radius: var(--radius-s);
    color: var(--color-danger);
    font-size: var(--text-3xs);
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
}

.trade-row__badge--done {
    border-color: var(--color-success);
    color: var(--color-success);
}

.trade-row__badge--expired,
.trade-row__badge--closed {
    border-color: var(--color-border-strong);
    color: var(--color-text-muted);
}

.trade-row__offers {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3xs);
    color: var(--color-text-muted);
}

/* ============ An item ============ */
.trade-item {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2xs);
    min-width: 0;
    text-decoration: none;
}

.trade-item:hover .trade-item__name,
.trade-item:focus-visible .trade-item__name {
    text-decoration: underline;
}

.trade-item__figure {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 2.75rem;
    height: 2.75rem;
    background: var(--color-surface-sunken);
    border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-s);
}

.trade-item__icon {
    max-width: 2.5rem;
    max-height: 2.5rem;
    object-fit: contain;
}

.trade-item--small .trade-item__figure {
    width: auto;
    height: auto;
    background: none;
    border: 0;
}

.trade-item--small .trade-item__icon {
    max-width: 1.25rem;
    max-height: 1.25rem;
}

.trade-item__name {
    font-weight: 600;
    color: var(--color-text-strong);
}

.trade-item--large .trade-item__name {
    font-size: var(--text-m);
}

.trade-item__qty {
    color: var(--color-text-strong);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.trade-item__note {
    color: var(--color-text-muted);
    font-size: var(--text-xs);
}

/* Names in the game's rarity colours (the picker shares them). */
.trade-picker__name--common {
    color: var(--color-text-strong);
}

.trade-item__name--magical,
.trade-picker__name--magical {
    color: var(--color-rarity-magical);
}

.trade-item__name--rare,
.trade-picker__name--rare {
    color: var(--color-rarity-rare);
}

.trade-item__name--epic,
.trade-picker__name--epic {
    color: var(--color-rarity-epic);
}

.trade-item__name--legendary,
.trade-picker__name--legendary {
    color: var(--color-rarity-legendary);
}

.trade-item__name--lesser,
.trade-picker__name--lesser,
.trade-item__name--greater,
.trade-picker__name--greater,
.trade-item__name--divine,
.trade-picker__name--divine {
    color: var(--color-rarity-artifact);
}

/* ============ A listing ============ */
.trade__kicker {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-xs);
}

.trade__state {
    color: var(--color-text-muted);
}

.trade__state--done {
    color: var(--color-success);
}

.trade__author {
    text-transform: none;
    letter-spacing: 0;
    font-size: var(--text-xs);
}

.trade__error {
    margin-bottom: var(--space-m);
}

.trade__deal {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
    gap: var(--space-m);
    align-items: start;
}

.trade__side {
    display: grid;
    gap: var(--space-xs);
    min-width: 0;
}

.trade__label {
    margin: 0;
    font-size: var(--text-xs);
    letter-spacing: var(--tracking-wider);
    text-transform: uppercase;
    color: var(--color-text-muted);
}

.trade__gone {
    margin: 0;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
}

.trade__wants {
    display: grid;
    gap: var(--space-2xs);
    margin: 0;
    padding: 0;
    list-style: none;
}

.trade__wants-text {
    margin: 0;
}

.trade__text {
    margin-top: var(--space-m);
    padding-top: var(--space-s);
    border-top: var(--border-thin) solid var(--color-border);
    color: var(--color-text-reading);
    line-height: var(--leading-reading);
}

.trade__contact {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2xs);
    margin: var(--space-m) 0 0;
}

/* ---- The author's controls ---- */
.trade-manage {
    display: grid;
    gap: var(--space-s);
    margin-top: var(--space-m);
    padding: var(--space-s);
    background: var(--color-surface-sunken);
    border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-m);
}

.trade-manage__row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2xs);
}

.trade-manage__form {
    margin: 0;
}

.trade-manage__done {
    display: grid;
    gap: var(--space-3xs);
    margin: 0;
}

/* One height for the select and the buttons beside it: each sizes itself from its own padding otherwise. */
.trade-manage__select,
.trade-manage .button {
    height: 2.5rem;
    padding-block: 0;
}

.trade-manage__select {
    flex: 1 1 12rem;
    max-width: 20rem;
}

/* ---- Feedback ---- */
.trade-feedback {
    display: grid;
    gap: var(--space-xs);
    margin-top: var(--space-m);
    padding-top: var(--space-s);
    border-top: var(--border-thin) solid var(--color-border);
}

.trade-feedback__deal {
    margin: 0;
}

.trade-feedback__list {
    display: grid;
    gap: var(--space-2xs);
    margin: 0;
    padding: 0;
    list-style: none;
}

.trade-feedback__item {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: var(--space-3xs) var(--space-xs);
    padding: var(--space-2xs) var(--space-xs);
    border-inline-start: 3px solid var(--color-success);
    background: var(--color-surface-sunken);
    border-radius: var(--radius-s);
}

.trade-feedback__item--neg {
    border-inline-start-color: var(--color-danger);
}

.trade-feedback__mark {
    font-weight: 700;
    color: var(--color-success);
}

.trade-feedback__item--neg .trade-feedback__mark {
    color: var(--color-danger);
}

.trade-feedback__who {
    color: var(--color-text-muted);
    font-size: var(--text-xs);
}

.trade-feedback__body {
    flex-basis: 100%;
}

.trade-feedback__remove {
    margin: 0 0 0 auto;
}

.trade-feedback__remove-button {
    padding: 0;
    background: none;
    border: 0;
    color: var(--color-text-muted);
    font-size: var(--text-2xs);
    cursor: pointer;
}

.trade-feedback__remove-button:hover {
    color: var(--color-danger);
}

.trade-feedback__form {
    display: grid;
    gap: var(--space-2xs);
    max-width: 32rem;
}

.trade-feedback__rating {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-s);
    margin: 0;
    padding: 0;
    border: 0;
}

.trade-feedback__rating .auth-form__label {
    flex-basis: 100%;
}

.trade-feedback__choice {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3xs);
    cursor: pointer;
}

.trade-feedback__choice--pos {
    color: var(--color-success);
}

.trade-feedback__choice--neg {
    color: var(--color-danger);
}

/* ============ Form ============ */
.trade-page {
    max-width: var(--container-narrow);
}

.trade-form {
    display: grid;
    gap: var(--space-m);
    padding: var(--space-l);
    background: var(--color-surface);
    border: var(--border-thin) solid var(--color-border);
}

@media (max-width: 40rem) {
    .trade-form {
        padding: var(--space-l) var(--space-m);
    }
}

.trade-form__group {
    display: grid;
    gap: var(--space-2xs);
    margin: 0;
    padding: 0;
    border: 0;
    min-width: 0;
}

.trade-form__group[hidden] {
    display: none;
}

.trade-form__switch {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2xs);
}

.trade-form__option {
    position: relative;
    cursor: pointer;
}

/* The radio stays for keyboards and screen readers; the label is the button. */
.trade-form__radio {
    position: absolute;
    opacity: 0;
}

.trade-form__option-text {
    display: inline-block;
    padding: var(--space-2xs) var(--space-s);
    border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-s);
    color: var(--color-text-muted);
}

.trade-form__radio:checked + .trade-form__option-text {
    border-color: var(--color-border-accent);
    background: var(--color-surface-raised);
    color: var(--color-heading);
}

.trade-form__radio:focus-visible + .trade-form__option-text {
    box-shadow: 0 0 0 3px var(--color-accent-soft);
}

.trade-form__actions {
    margin: 0;
}

/* ---- Picker ---- */
.trade-picker {
    position: relative;
    display: grid;
    gap: var(--space-2xs);
}

.trade-picker__chosen {
    display: grid;
    gap: var(--space-3xs);
    margin: 0;
    padding: 0;
    list-style: none;
}

.trade-picker__chosen:empty {
    display: none;
}

.trade-picker__pick {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2xs);
    padding: var(--space-3xs) var(--space-2xs);
    background: var(--color-surface-sunken);
    border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-s);
}

.trade-picker__figure {
    display: inline-flex;
    width: 2rem;
    height: 2rem;
    align-items: center;
    justify-content: center;
}

.trade-picker__icon {
    max-width: 2rem;
    max-height: 2rem;
    object-fit: contain;
}

/* No colour here: this rule comes after the rarity colours and would override them. */
.trade-picker__name {
    font-weight: 600;
}

.trade-picker__note {
    color: var(--color-text-muted);
    font-size: var(--text-xs);
}

.trade-picker__variant {
    height: 2rem;
    padding-block: 0;
    font-size: var(--text-xs);
}

/* The count sits on the right, before the cross. */
.trade-picker__qty {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3xs);
    margin-inline-start: auto;
    color: var(--color-text-muted);
}

.trade-picker__qty-field {
    width: 4rem;
    height: 2rem;
    padding: 0 var(--space-2xs);
    font-size: var(--text-s);
    text-align: center;
}

.trade-picker__remove {
    padding: 0 var(--space-2xs);
    background: none;
    border: 0;
    color: var(--color-text-muted);
    font-size: var(--text-l);
    line-height: 1;
    cursor: pointer;
}

.trade-picker__remove:hover {
    color: var(--color-danger);
}

.trade-picker__results {
    position: absolute;
    top: 100%;
    inset-inline: 0;
    z-index: 20;
    max-height: 22rem;
    margin: var(--space-3xs) 0 0;
    padding: var(--space-3xs);
    overflow-y: auto;
    list-style: none;
    background: var(--color-surface-raised);
    border: var(--border-thin) solid var(--color-border-strong);
    border-radius: var(--radius-s);
    box-shadow: var(--shadow-m);
}

.trade-picker__option {
    display: flex;
    align-items: center;
    gap: var(--space-2xs);
    width: 100%;
    padding: var(--space-3xs) var(--space-2xs);
    background: none;
    border: 0;
    border-radius: var(--radius-s);
    color: inherit;
    text-align: start;
    cursor: pointer;
}

.trade-picker__option:hover,
.trade-picker__option:focus-visible {
    background: var(--color-surface-hover);
}

/* A whole set stands apart from single items: a stripe and a lighter ground. */
.trade-picker__option--set,
.trade-picker__pick--set {
    border-inline-start: 3px solid var(--color-border-accent);
    background: var(--color-surface-hover);
}

.trade-picker__option--set {
    border-radius: 0 var(--radius-s) var(--radius-s) 0;
}

.trade-picker__option[disabled] {
    opacity: 0.45;
    cursor: default;
}

.trade-picker__text {
    display: grid;
}

.trade-picker__empty {
    padding: var(--space-2xs);
    color: var(--color-text-muted);
    font-size: var(--text-xs);
}

.trade-form__wants-text {
    width: 100%;
}

/* ============ An item's deals, under its page in the base ============ */
.db-trades {
    display: grid;
    gap: var(--space-m);
    margin-top: var(--space-m);
    padding: var(--space-l);
    background: var(--color-surface);
    border: var(--border-thin) solid var(--color-border);
}

@media (max-width: 40rem) {
    .db-trades {
        padding: var(--space-l) var(--space-m);
    }
}

.db-trades__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-xs);
}

.db-trades__title {
    margin: 0;
}

.db-trades__group {
    display: grid;
    gap: var(--space-xs);
}

.db-trades__subtitle {
    display: flex;
    align-items: center;
    gap: var(--space-2xs);
    margin: 0;
    font-size: var(--text-xs);
    letter-spacing: var(--tracking-wider);
    text-transform: uppercase;
    color: var(--color-text-muted);
}

.db-trades__count {
    padding: 0 var(--space-2xs);
    border: var(--border-thin) solid var(--color-border);
    border-radius: var(--radius-s);
    font-variant-numeric: tabular-nums;
    letter-spacing: 0;
}

.db-trades__more {
    margin: 0;
    font-size: var(--text-xs);
}

.db-trades__more a {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3xs);
}

/* Rows on a profile card sit a step down from it too. */
.profile-list .trade-row {
    background: var(--color-surface-sunken);
}
