body.listing-page:not(.batch-create-mode):has(#topbarBatchChip:not([hidden])) { --throne-page-top: 8px; }

body.listing-page .topbar.listing-header {
    container-type: inline-size;
    padding: 0;
    border-radius: 8px;
    margin: 8px 16px 0;
    background: var(--bg-card, var(--surface));
    overflow: visible;
    position: sticky;
    top: 0;
}
.topbar.listing-header .topbar-right { display: block; flex: 1 1 auto; margin: 0; }
.listing-header #topbarBatchChip {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    width: 100%;
    max-width: none;
    padding: 6px 14px;
    border: 0;
    border-radius: 0;
    flex-wrap: wrap;
    background: transparent;
    font-weight: 400;
}
.listing-header [hidden] { display: none !important; }
.listing-header details { position: relative; }
.listing-header summary { list-style: none; cursor: pointer; }
.listing-header summary::-webkit-details-marker { display: none; }
/* Grow into free space rather than claiming it up front: a wide basis wrapped the
   List-only Sort and Bulk Edit controls onto a second row at mid widths, so the
   loaded topbar height depended on the view. */
.listing-header .listing-batch-details { flex: 1 1 140px; min-width: 110px; max-width: 260px; }
.listing-header .listing-batch-details summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 48px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-primary);
}
.listing-batch-summary-copy { display: grid; gap: 3px; min-width: 0; text-align: left; }
.listing-batch-summary-copy strong { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.listing-batch-summary-copy > span { font-size: 11px; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.listing-header svg { width: 18px; height: 18px; flex: 0 0 18px; }
.listing-header .listing-header-button svg[fill="none"] { stroke: currentColor; }
.listing-header .listing-toolbar-controls { display: flex; flex-wrap: wrap; gap: 10px; width: auto; min-width: 0; flex: 0 1 auto; }
.listing-header #viewModeToggleGroup { margin: 0 !important; width: auto; padding: 0; border-radius: 6px; }
.listing-header .scan-mode-btn { min-height: 40px; padding: 0 16px; font-size: 12px; border-radius: 5px; }
html[data-throne-theme="dark"] .listing-header #viewModeToggleGroup .scan-mode-btn.active {
    --throne-selection-bg: #ededed;
    --throne-selection-border: #ededed;
    --throne-text-primary: #161616;
}
.listing-header .topbar-action-group { margin-left: auto; display: flex; flex: 0 0 auto; flex-wrap: nowrap; gap: 10px; padding: 0; border: 0; }
.listing-header .listing-header-button,
.listing-header .topbar-batch-icon-button,
.listing-header .listing-sort-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    height: 40px;
    width: auto;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    background: var(--bg-input);
    box-shadow: none;
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
}
.listing-header #topbarSaveBtn,
.listing-header #listingActionsSummary { width: 40px; padding: 0; }
.listing-header #topbarSaveBtn { flex: 0 0 40px; max-width: 40px; }
.listing-header button:disabled { opacity: 0.45; cursor: not-allowed; }
.listing-header button:hover:not(:disabled),
.listing-header summary:hover { border-color: var(--text-muted); }
.listing-header button:focus-visible,
.listing-header summary:focus-visible { outline: 2px solid var(--text-primary); outline-offset: 3px; }
.listing-header .listing-header-popover {
    position: absolute;
    top: calc(100% + 10px);
    z-index: 120;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card, var(--surface));
    box-shadow: 0 12px 36px #0003;
    padding: 16px;
}
.listing-header .listing-batch-form { left: 0; width: 300px; display: grid; gap: 12px; }
.listing-header .listing-batch-form .topbar-sku-group { display: contents; }
.listing-header .listing-batch-form .topbar-batch-field { display: grid; grid-template-columns: 80px minmax(0, 1fr); align-items: center; gap: 12px; width: 100%; max-width: none; padding: 0; border: 0; background: transparent; }
.listing-header .listing-batch-form .topbar-field-kicker { font-size: 12px; color: var(--text-secondary); text-transform: none; letter-spacing: 0; }
/* The shared dark theme forces the former segmented fields to have a fill. */
html[data-throne-theme] #listingBatchDetails .listing-batch-form .topbar-batch-field,
html[data-throne-theme] #listingBatchDetails .listing-batch-form .topbar-field-kicker {
    background: transparent !important;
    border: 0 !important;
    padding: 0;
    font-weight: 400;
}
.listing-header .listing-batch-form input:not([type=checkbox]) { width: 100%; min-width: 0; height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: 5px; background: var(--bg-input); color: var(--text-primary); text-align: left; font-size: 13px; font-weight: 400; }
.listing-header .listing-batch-form input:focus-visible { outline: 2px solid var(--text-primary); outline-offset: 2px; }
.listing-header .listing-actions-panel { right: 0; width: 220px; padding: 8px; }
.listing-header .listing-header-menu-button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 12px; border: 0; border-radius: 5px; background: transparent; color: var(--text-primary); font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.listing-header .listing-header-menu-button:hover:not(:disabled) { background: var(--bg-input); }
.listing-header .listing-header-menu-button svg { display: none; }
.listing-header .listing-header-menu-button.delete { color: #ef6666; }
.listing-header .listing-header-menu-button { --throne-button-bg: transparent; --throne-button-hover: var(--bg-input); --throne-button-ink: var(--text-primary); font-weight: 400; }
.listing-header .listing-header-menu-button.delete { --throne-button-ink: #ef6666; }
.listing-header #listingActionsSummary .tr-icon { transform: rotate(90deg); }
.listing-actions-panel hr { margin: 6px 12px; border: 0; border-top: 1px solid var(--border); }
.listing-header-summary { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px 16px; width: 100%; border-top: 1px solid var(--border); padding: 4px 14px; }
.listing-header #topbarStatsPill { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; margin: 0; padding: 0; border: 0; background: transparent; box-shadow: none; min-height: 28px; }
.listing-header .topbar-stat { font-size: 12px; font-weight: 400; }
.listing-header .topbar-stat strong { color: var(--text-primary); font-weight: 600; }
.listing-header .topbar-cost-prefix { color: var(--text-primary); }
.listing-header .topbar-cost-prefix.is-derived-cost { color: var(--text-secondary); }
.listing-header .topbar-cost-input { border: 1px solid var(--border); border-radius: 5px; background: var(--bg-input); padding: 4px 7px; color: var(--text-primary); }
.listing-header .topbar-cost-input.is-derived-cost { color: var(--text-secondary); }
body:not(.listing-view-match) #scanner-authed-content .toolbar,
#scanner-authed-content .toolbar:has(> #matchToolbarWorkflow[hidden]) { display: none; }

#listViewGrid .lv-side-rail { grid-template-columns: minmax(0, 1fr) 30px; gap: 8px; }
#listViewGrid .lv-affiliate-stack { gap: 8px; width: 100%; align-self: start; }
#listViewGrid .lv-affiliate-btn { min-height: 30px; padding: 5px; border-radius: 7px; color: var(--text-primary); background: var(--bg-input); font-size: 9px; }
#listViewGrid .lv-row-actions { gap: 8px; }
#listViewGrid .lv-btn-icon { flex: 0 0 30px; width: 30px; height: 30px; border: 1px solid var(--border); background: var(--bg-input); border-radius: 7px; }
#listViewGrid .lv-btn-icon.confirming { background: rgba(239,68,68,0.12); border-color: rgba(239,68,68,0.42); color: #ef4444; }
@media (min-width: 1101px) {
    @container list-view (min-width: 1081px) {
        #listViewGrid .list-view-row { grid-template-columns: 24px var(--lv-thumb-column-width) minmax(0, 1fr) 136px; }
        #listViewGrid .list-view-row.graded-row { grid-template-columns: 24px 150px minmax(0, 1fr) 136px; }
        #listViewGrid .lv-side-rail { width: 136px; }
    }
}
@container list-view (max-width: 1080px) {
    #listViewGrid .lv-side-rail { grid-template-columns: minmax(0, 1fr) 68px; }
}
@media (max-width: 1100px) {
    #listViewGrid .lv-side-rail { grid-template-columns: minmax(0, 1fr) 68px; }
}

@container (max-width: 1000px) {
    .listing-header .listing-sort-button,
    .listing-header #bulkEditAllBtn { min-width: 0; }
    .listing-header #topbarBatchChip { gap: 8px; padding: 6px 8px; }
    .listing-header .listing-toolbar-controls,
    .listing-header .topbar-action-group { gap: 6px; }
    .listing-header .scan-mode-btn { padding: 0 12px; }
    .listing-header .listing-header-button,
    .listing-header .listing-sort-button { padding: 0 8px; gap: 6px; }
}
@container (max-width: 900px) {
    .listing-header #topbarDirectEbayBtn > span,
    .listing-header #topbarExportBtn > span { display: none; }
    .listing-header #topbarDirectEbayBtn,
    .listing-header #topbarExportBtn { width: 40px; }
}
@container (max-width: 570px) {
    .listing-header #topbarBatchChip { flex-wrap: wrap; }
    .listing-header .listing-batch-details { flex: 1 1 100px; min-width: 100px; max-width: none; }
    .listing-header #topbarSaveBtn { flex-basis: 36px; max-width: 36px; }
    .listing-header #topbarSaveBtn,
    .listing-header #topbarDirectEbayBtn,
    .listing-header #topbarExportBtn,
    .listing-header #listingActionsSummary { width: 36px; }
    /* The controls get their own row here. It keeps the view toggle's height whether
       the batch shows controls (singles, lots, stock) or none (slabs), so the topbar
       is one height while a batch route loads and after either shape renders. */
    .listing-header .listing-toolbar-controls { order: 3; justify-content: flex-start; width: 100%; min-height: 44px; }
    .listing-header #viewModeToggleGroup,
    .listing-header #listingSortMenu { flex: 0 0 auto; width: auto; }
    .listing-header #viewModeToggleGroup .scan-mode-btn { min-width: 46px; padding: 0 8px; }
    .listing-header .listing-sort-button,
    .listing-header #bulkEditAllBtn { min-width: 0; width: auto; font-size: 11px; }
    .listing-header .listing-sort-chevron,
    .listing-header #bulkEditAllBtn svg { display: none; }
    .listing-header #topbarStatsPill { gap: 7px; }
    .listing-header .topbar-stat { font-size: 11px; }
}
@media (max-width: 1024px) {
    body.listing-page .topbar.listing-header { margin: 8px 8px 0 56px; }
    .listing-header .listing-batch-form { width: min(300px, calc(100vw - 82px)); }
}
