/*
 * The marketplace (trade.js, collection.js): the header's Collections link
 * and cart, listing cards, the collection pages, the buy / list / cancel
 * dialogs, and the address page's market column and listings. Built on
 * app.css's theme tokens, so light, dark and auto follow the page; the CSP
 * allows no inline style, so every state is a class here. Everything in it
 * shows only while the market is on (trade.js adds it to the page).
 */

/* ------------------------------------------------------------- header */

/* The brand link, the nav links and the cart's place: header.css. */

.trade-cart-btn {
    position: relative;
    height: 30px;
    padding: 0 8px;
    color: var(--ink-2);
    font-size: 13px;
}

.trade-cart-btn:hover {
    color: var(--ink);
}

.trade-cart-icon {
    width: 16px;
    height: 16px;
}

.btn .trade-cart-icon path {
    fill: none;
    stroke-linejoin: round;
}

.trade-cart-count {
    min-width: 16px;
    padding: 0 4px;
    line-height: 16px;
    font-size: 10.5px;
}

/* ------------------------------------------------------------ buttons */

.btn--small {
    height: 28px;
    padding: 0 10px;
    font-size: 12.5px;
}

.btn--primary {
    border-color: var(--ink);
    background: var(--ink);
    color: var(--surface);
    font-weight: 600;
}

.btn--primary:hover {
    background: color-mix(in srgb, var(--ink) 84%, var(--surface));
}

.btn--quiet {
    border-color: var(--grid);
    color: var(--ink-2);
}

.btn--danger {
    border-color: var(--critical);
    background: var(--critical);
    color: #ffffff;
    font-weight: 600;
}

.btn--danger:hover {
    background: color-mix(in srgb, var(--critical) 85%, var(--ink));
}

.btn:disabled,
.btn[disabled] {
    cursor: not-allowed;
    opacity: 0.5;
}

.btn--primary:disabled:hover {
    background: var(--ink);
}

/* ------------------------------------------------------------- prices */

.unit-price {
    display: inline-flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 0 0.28em;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.unit-price-unit,
.unit-price-per {
    color: var(--ink-2);
    font-size: 0.86em;
}

.unit-price .btc {
    align-self: center;
}

.market-none {
    opacity: 0.4;
}

/* Listed: "+3", the listings holding one in a bundle (never counted). */
.market-contains {
    color: var(--muted);
    font-size: 11.5px;
}

/* The leaderboard with Floor and Listed: the share keeps its number and
   gives up its meter below 1440 px, so the table still fits. */
@media (min-width: 1100px) and (max-width: 1439.98px) {
    :root.market-on .market-content {
        grid-template-columns: minmax(0, 1fr) minmax(300px, 330px);
    }
}

@media (max-width: 1439.98px) {
    .market-table--listings .market-share {
        min-width: 0;
    }

    .market-table--listings .market-share .meter {
        display: none;
    }
}

/* ------------------------------------------------------- listing cards */

.lcard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    padding: 12px 16px 16px;
    transition: opacity 0.2s ease;
}

.lcard-grid.is-loading {
    opacity: 0.55;
}

.lcard {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 0;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--sunken);
}

.lcard:hover,
.lcard:focus-within {
    border-color: var(--control-border);
}

.lcard--pending {
    opacity: 0.7;
}

.lcard-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}

.lcard-bulk {
    flex: none;
    padding: 1px 8px;
    border-radius: 9999px;
    background: var(--ink);
    color: var(--surface);
    font-size: 12px;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
}

.lcard-sat {
    display: flex;
    min-width: 0;
    color: var(--ink-2);
    font-size: 12.5px;
}

.lcard-sat .mono {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.lcard-year {
    flex: none;
    white-space: pre;
}

.lcard-row {
    color: var(--ink-2);
    font-size: 12.5px;
}

.lcard-price {
    display: grid;
    gap: 2px;
    margin-top: auto;
}

.lcard-unit {
    font-size: 20px;
    font-weight: 650;
    line-height: 1.2;
}

.lcard-unit .unit-price-unit,
.lcard-unit .unit-price-per {
    font-size: 13px;
    font-weight: 500;
}

.lcard-unit .btc-mark {
    width: 11px;
    height: 16px;
}

.lcard-total {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0 4px;
    color: var(--ink-2);
    font-size: 13px;
}

.lcard-total-btc {
    color: var(--ink);
    font-weight: 600;
}

.lcard-note {
    color: var(--ink-2);
    font-size: 11.5px;
    line-height: 1.35;
}

/* In bundle (a collection's "Also contains"): no unit price of this row,
   the whole UTXO's price large instead. */
.lcard-unit--whole {
    color: var(--ink-2);
    font-size: 12.5px;
    font-weight: 500;
}

.lcard--bundle .lcard-total-btc {
    font-size: 17px;
}

.lcard-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.lcard-actions .btn--primary {
    flex: 1 1 auto;
    justify-content: center;
}

.lcard-cart[aria-pressed="true"] {
    background: var(--chip);
    font-weight: 600;
}

.lcard-status {
    color: var(--ink-2);
    font-size: 12.5px;
}

.lcard-status--own {
    flex: 1 1 100%;
    font-weight: 600;
    color: var(--ink);
}

.trade-chips {
    min-width: 0;
}

/* ---------------------------------------------------- collection pages */

/* The collection pane alone, whatever the width (as the address pane). */
.panes.is-collection {
    display: flex;
}

.panes.is-collection > .pane:not(.pane--collection),
.panes:not(.is-collection) > .pane--collection {
    display: none;
}

/* The page scrolls as one: the head (crumbs, title, numbers) goes up with
   the content and the tabs, with the tab's bar under them, stay at the top
   (.coll-sticky), so a tab's list gets the screen. Isolated: the sticky
   bar's z-index stays inside the pane, under the header's menus. */
.pane--collection {
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    isolation: isolate;
}

.pane--collection > .coll-head {
    flex: none;
}

.coll-head {
    display: grid;
    gap: 6px;
    align-items: start;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--grid);
}

.coll-crumbs {
    color: var(--ink-2);
    font-size: 12.5px;
}

.coll-title-line {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.pane--collection .coll-head h2 {
    font-size: 20px;
}

.coll-stats,
.coll-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
    gap: 8px;
    margin: 4px 0 0;
}

.coll-stat {
    display: grid;
    align-content: start;
    gap: 1px;
    min-width: 0;
    padding: 6px 10px 7px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--sunken);
}

.coll-stat dd {
    margin: 0;
}

.coll-stat-label {
    color: var(--ink-2);
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.coll-stat-value {
    font-size: 16px;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.coll-stat-value .unit-price-unit,
.coll-stat-value .unit-price-per {
    font-size: 12px;
    font-weight: 500;
}

.coll-stat-sub {
    color: var(--ink-2);
    font-size: 11.5px;
}

.coll-body {
    flex: 1 0 auto;
    /* At least the pane's height: the tabs can always reach the top, so a
       short tab doesn't pull the head back in under the reader. */
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

/* The server's copy of a collection for crawlers (seoPages.js), until the
   view replaces it. */
.coll-seo {
    margin: 12px 16px 0;
    max-width: 72ch;
    color: var(--ink-2);
}

/* The tabs, and the listings' bar (sort, Cards | Grid, count): stuck to
   the top of the pane once the head has scrolled away. */
.coll-sticky {
    position: sticky;
    top: 0;
    z-index: 4;
    flex: none;
    background: var(--surface);
}

.coll-tabs {
    display: flex;
    gap: 2px;
    padding: 0 12px;
    border-bottom: 1px solid var(--grid);
    overflow-x: auto;
    scrollbar-width: none;
}

.coll-panel {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
}

.coll-bar {
    justify-content: space-between;
}

/* The tab's content, in the page's scroll (a table scrolls sideways in its
   own frame, .table-x / .lgrid-x). */
.coll-scroll {
    flex: 1 0 auto;
}

.coll-scroll > .table-x {
    padding: 0 16px 16px;
}

.coll-scroll > .coll-tiles {
    padding: 12px 16px 0;
}

.coll-missing a {
    font-weight: 600;
}

.coll-activity .coll-event {
    font-weight: 600;
}

.coll-event--sold {
    color: color-mix(in srgb, var(--good) 70%, var(--ink));
}

.coll-event--cancelled,
.coll-event--moved {
    color: var(--ink-2);
}

.coll-row--muted td {
    color: var(--ink-2);
}

.coll-flag {
    color: var(--ink-2);
    font-size: 12px;
}

/* "Also contains": the listings of other categories holding some of this
   row's sats in a bundle, below the listings, quiet. */
.coll-contains {
    margin-top: 8px;
    border-top: 1px solid var(--grid);
}

.coll-contains-title {
    margin: 0;
    padding: 14px 16px 0;
    color: var(--ink-2);
    font-size: 13px;
    font-weight: 650;
}

.coll-contains-count {
    font-weight: 500;
}

.coll-contains-note {
    max-width: 72ch;
    margin: 2px 0 0;
    padding: 0 16px;
}

.coll-contains > .lgrid-x {
    margin: 10px 16px 16px;
    padding: 0;
}

.lgrid-contains {
    display: inline-block;
    min-width: 17em;
    white-space: normal;
}

/* Nothing priced, bundles below: the empty note stays short so "Also
   contains" is in view. */
.addr-state.coll-state--short {
    min-height: 0;
    padding: 20px 16px 12px;
}

@media (max-width: 719.98px) {
    .coll-contains-title {
        padding: 12px 12px 0;
    }

    .coll-contains-note {
        padding: 0 12px;
    }

    .coll-contains > .lgrid-x {
        margin: 8px 0 12px;
    }
}

.coll-holders-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 16px;
    padding: 12px 16px 16px;
}

.coll-holders h3 {
    font-size: 13px;
    font-weight: 650;
}

.coll-holders .trade-small {
    margin-bottom: 6px;
}

.coll-rank {
    width: 1%;
    color: var(--ink-2);
}

/* ------------------------------------------------------------- dialogs */

dialog.trade-dialog {
    width: min(480px, calc(100vw - 24px));
    max-height: calc(100dvh - 24px);
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow);
    overflow: hidden;
}

dialog.trade-dialog--wide {
    width: min(640px, calc(100vw - 24px));
}

dialog.trade-dialog[open] {
    display: flex;
    flex-direction: column;
}

dialog.trade-dialog::backdrop {
    background: var(--backdrop);
}

.trade-head {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 10px 6px 20px;
}

.trade-title {
    font-size: 17px;
    font-weight: 650;
}

.trade-title:focus,
.trade-title:focus-visible {
    outline: none;
}

.trade-body {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    align-content: start;
    gap: 14px;
    padding: 6px 20px 16px;
    overflow: auto;
    overscroll-behavior: contain;
}

.trade-foot {
    flex: none;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
    padding: 12px 20px 16px;
    border-top: 1px solid var(--grid);
}

.trade-lead {
    color: var(--ink-2);
    font-size: 13.5px;
}

.trade-small {
    color: var(--ink-2);
    font-size: 12px;
}

.trade-muted {
    color: var(--ink-2);
}

.trade-note {
    padding: 9px 12px;
    border-radius: var(--radius);
    background: var(--wash);
    font-size: 12.5px;
    line-height: 1.45;
}

.trade-alert {
    padding: 9px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    border-left: 3px solid var(--critical);
    background: color-mix(in srgb, var(--critical) 9%, var(--surface));
}

.trade-alert--warning {
    border-left-color: var(--warning);
    background: color-mix(in srgb, var(--warning) 13%, var(--surface));
}

.trade-busy {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 0;
    color: var(--ink-2);
}

.trade-spinner {
    flex: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--grid);
    border-top-color: var(--ink);
    border-radius: 50%;
    animation: trade-spin 0.8s linear infinite;
}

@keyframes trade-spin {
    to {
        transform: rotate(360deg);
    }
}

.trade-wallets {
    display: grid;
    gap: 8px;
}

.trade-wallet {
    justify-content: center;
    height: 40px;
    text-decoration: none;
}

.trade-items {
    display: grid;
    gap: 0;
    margin: 0;
    padding: 0;
    list-style: none;
}

.trade-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 0;
    padding: 10px 0;
    border-bottom: 1px solid var(--grid);
}

.trade-item:first-child {
    padding-top: 0;
}

.trade-item--problem .trade-item-main {
    opacity: 0.6;
}

.trade-item-main {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.trade-item-main .addr-chips {
    flex: none;
    max-width: 45%;
}

.trade-item-text {
    display: grid;
    min-width: 0;
}

.trade-item-row {
    font-weight: 600;
}

.trade-item-sat {
    overflow: hidden;
    color: var(--ink-2);
    font-size: 12px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.trade-item-problem {
    color: var(--critical);
    font-size: 12px;
}

.trade-item-side {
    display: grid;
    justify-items: end;
    gap: 2px;
    flex: none;
}

.trade-item-unit {
    color: var(--ink-2);
    font-size: 12px;
}

.trade-summary {
    display: grid;
    gap: 6px;
    margin: 0;
}

.trade-summary-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
}

.trade-summary dt {
    color: var(--ink-2);
}

.trade-summary dd {
    margin: 0;
    text-align: right;
}

.trade-summary-total {
    padding-top: 8px;
    border-top: 1px solid var(--grid);
    font-weight: 650;
}

.trade-summary-total dt {
    color: var(--ink);
}

.trade-expiry {
    font-variant-numeric: tabular-nums;
}

.trade-fees {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
    gap: 8px;
    margin: 0;
    padding: 0;
    border: 0;
}

.trade-fees legend {
    margin-bottom: 6px;
    padding: 0;
    font-weight: 600;
}

.trade-fee {
    position: relative;
    display: flex;
    gap: 8px;
    padding: 9px 10px;
    border: 1px solid var(--grid);
    border-radius: var(--radius);
    cursor: pointer;
}

.trade-fee:has(input:checked) {
    border-color: var(--ink);
    box-shadow: inset 0 0 0 1px var(--ink);
}

.trade-fee input[type="radio"] {
    margin: 2px 0 0;
    accent-color: var(--ink);
}

.trade-fee-text {
    display: grid;
    gap: 1px;
    min-width: 0;
}

.trade-fee-name {
    font-weight: 600;
}

.trade-fee-rate {
    font-variant-numeric: tabular-nums;
}

.trade-fee-sub {
    color: var(--ink-2);
    font-size: 11.5px;
}

.trade-input {
    width: 100%;
    min-width: 0;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--control-border);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-variant-numeric: tabular-nums;
}

.trade-input[aria-invalid="true"] {
    border-color: var(--critical);
    box-shadow: inset 0 0 0 1px var(--critical);
}

.trade-fee-custom {
    height: 28px;
    margin-top: 3px;
}

.trade-field {
    display: grid;
    gap: 4px;
}

.trade-field label {
    font-weight: 600;
}

.trade-payout {
    font-family: var(--mono);
    font-size: 12.5px;
}

.trade-list-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.trade-all {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 10px;
    border-radius: var(--radius);
    background: var(--sunken);
}

.trade-all label {
    font-size: 12.5px;
    font-weight: 600;
}

.trade-all .trade-price-box {
    width: 160px;
}

.trade-list-item {
    align-items: flex-start;
}

.trade-price-field {
    display: grid;
    gap: 3px;
    flex: none;
    width: 220px;
}

.trade-price-label {
    color: var(--ink-2);
    font-size: 12px;
}

.trade-price-box {
    position: relative;
    display: flex;
    align-items: center;
}

.trade-price-box .trade-input {
    padding-right: 76px;
    text-align: right;
}

.trade-price-suffix {
    position: absolute;
    right: 10px;
    color: var(--ink-2);
    font-size: 12px;
    pointer-events: none;
}

.trade-price-other {
    min-height: 1.4em;
    color: var(--ink-2);
    font-size: 12px;
    text-align: right;
}

.trade-price-other .unit-price {
    color: var(--ink);
}

.trade-price-problem {
    color: var(--critical);
    font-size: 12px;
    text-align: right;
}

.trade-price-problem:empty {
    display: none;
}

/* The price's anchor (list-prefill.js): its source, quiet, and quick prices. */
.trade-price-source {
    color: var(--ink-2);
    font-size: 11.5px;
    line-height: 1.35;
    text-align: right;
}

.trade-price-choices {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
}

.trade-price-choice {
    min-height: 24px;
    padding: 0 8px;
    border: 1px solid var(--grid);
    border-radius: 999px;
    background: transparent;
    color: var(--ink-2);
    font: inherit;
    font-size: 11.5px;
    cursor: pointer;
}

.trade-price-choice:hover {
    border-color: var(--ink-2);
    color: var(--ink);
}

.trade-price-choice[aria-pressed="true"] {
    border-color: var(--ink);
    background: var(--ink);
    color: var(--surface);
}

.trade-price-choice:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 1px;
}

.trade-txid {
    overflow-wrap: anywhere;
}

/* ------------------------------------------------- the address page */

.trade-addr {
    flex: none;
    max-height: 45vh;
    overflow: auto;
    border-bottom: 1px solid var(--grid);
    background: var(--sunken);
}

.trade-addr-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    padding: 8px 16px;
}

.trade-addr-hint {
    flex: 1 1 auto;
    color: var(--ink-2);
    font-size: 12.5px;
}

.trade-addr-count {
    font-size: 12.5px;
    font-weight: 600;
}

.trade-mine {
    padding: 0 16px 10px;
}

.trade-mine summary {
    cursor: pointer;
    padding: 4px 0;
    font-weight: 600;
}

.trade-mine-count {
    color: var(--ink-2);
    font-weight: 400;
}

.trade-mine-table {
    margin-top: 6px;
}

.trade-mine-actions {
    white-space: nowrap;
}

.trade-mine-actions .btn + .btn {
    margin-left: 6px;
}

.trade-mine-foot {
    display: flex;
    justify-content: flex-end;
    padding-top: 8px;
}

.trade-mine-empty {
    padding: 4px 0;
}

.addr-table .col-market {
    white-space: nowrap;
}

.trade-cell {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.trade-check {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--ink);
}

.trade-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 9999px;
    background: color-mix(in srgb, var(--good) 14%, var(--surface));
    font-size: 12px;
    font-weight: 600;
}

.trade-tag--pending {
    background: color-mix(in srgb, var(--warning) 18%, var(--surface));
}

.trade-exposed {
    display: block;
    max-width: 34em;
    color: var(--ink-2);
    font-size: 12px;
    line-height: 1.4;
    white-space: normal;
}

.trade-exposed strong {
    color: var(--critical);
}

.trade-exposed-short {
    color: var(--critical);
    font-size: 12px;
}

/* ------------------------------------------------------------- phones */

@media (max-width: 719.98px) {
    .site-nav {
        padding-right: 4px;
    }

    .coll-stats {
        gap: 6px;
    }

    .coll-stat-value {
        font-size: 14.5px;
    }

    .coll-bar select {
        max-width: 60vw;
    }

    /* The count the Listings tab already shows: a line less stuck at the top. */
    .coll-sticky .coll-meta--count {
        display: none;
    }

    .trade-cart-label {
        display: none;
    }

    .lcard-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 8px;
        padding: 10px 12px 12px;
    }

    .lcard {
        padding: 10px;
    }

    .lcard-unit {
        font-size: 17px;
    }

    .coll-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .coll-stat {
        padding: 5px 9px 6px;
    }

    .pane--collection .pane-head h2 {
        position: static;
        width: auto;
        height: auto;
        overflow: visible;
        clip-path: none;
        white-space: normal;
    }

    dialog.trade-dialog,
    dialog.trade-dialog--wide {
        width: calc(100vw - 16px);
        max-height: calc(100dvh - 16px);
        margin: auto auto 8px;
    }

    .trade-body {
        padding: 6px 14px 14px;
    }

    .trade-head {
        padding-left: 14px;
    }

    .trade-foot {
        padding: 10px 14px 14px;
    }

    .trade-foot .btn {
        flex: 1 1 auto;
        justify-content: center;
    }

    .trade-item,
    .trade-list-item {
        flex-wrap: wrap;
    }

    .trade-price-field {
        width: 100%;
    }

    .trade-item-side {
        justify-items: start;
    }
}

@media (prefers-reduced-motion: reduce) {
    .trade-spinner {
        animation-duration: 2.4s;
    }
}

@media (forced-colors: active) {
    .btn--primary,
    .btn--danger,
    .lcard-bulk {
        border: 1px solid ButtonText;
    }

    .trade-fee:has(input:checked) {
        border: 2px solid Highlight;
    }

    .trade-price-choice[aria-pressed="true"] {
        border: 2px solid Highlight;
    }
}

/* A listing whose UTXO a transaction in the mempool spends (trade.js). */
.lcard-status--pending {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.coll-reprice {
    white-space: nowrap;
}
