/* Item Lookup — layout + modal */

/* Page title — match Market / Product Analysis underlined header */
#item-lookup .market-header h2 {
  text-align: left;
  font-size: 1.8rem;
  font-weight: 900;
  margin-top: 0;
  margin-bottom: var(--il-space-xl);
  color: var(--theme-explore-header-text);
  text-transform: uppercase;
  letter-spacing: 2.5px;
  text-shadow: var(--theme-explore-header-shadow);
  position: relative;
  display: block;
  width: 100%;
  padding-bottom: 12px;
  border-bottom: 4px solid var(--theme-accent-primary);
}

#item-lookup .market-header {
  text-align: left;
}

/* Vertical rhythm — Item Lookup only (item-lookup.css loads after components.css). */
#item-lookup {
  --il-space-xs: 8px;
  --il-space-sm: 12px;
  --il-space-md: 16px;
  --il-space-lg: 20px;
  --il-space-xl: 24px;
  --il-stack-gap: 20px;
  --il-inner-gap: 14px;
  --il-card-pad-y: 20px;
  --il-card-pad-x: 22px;
  /* Cohort trend chart min height (Item Lookup top-right pane) */
  --il-chart-min: 180px;
  /* Product median line chart — taller chart area for median history */
  --il-product-chart-min: 220px;
  /*
   * Top row: fixed height (not driven by sparse pages). Must fit 10 products =
   * 5 grid rows (2 cols @ ≥520px) + section title + pager + card padding.
   * Per-row budget: 80px thumb + padding + a little extra so 2-line titles in a
   * narrow half-width column don’t force the grid to scroll.
   */
  --il-product-grid-row-min: calc(92px + (2 * var(--il-space-sm)));
  --il-top-row-fit-ten-products: calc(
    (var(--il-card-pad-y) + 2px)
    + (var(--il-card-pad-y) + 2px)
    + 2.75rem
    + (5 * var(--il-product-grid-row-min))
    + (4 * var(--il-inner-gap))
    + (2 * var(--il-inner-gap))
    + 3.75rem
  );
  /* Always at least --il-top-row-fit-ten-products (5×2 grid + title + pager); never cap below that */
  --il-top-row-height: min(96vh, max(var(--il-top-row-fit-ten-products), 34vh));
  --il-top-row-pane-stacked-height: clamp(300px, 42vh, 520px);
}

#item-lookup .item-lookup-layout {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#item-lookup .item-lookup-results-wrap:not([hidden]) {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#item-lookup .item-lookup-main-split {
  flex: 1 1 auto;
  min-height: 0;
  align-items: stretch;
}

/* Side-by-side top row: fixed outer height; inner panes always fill (no shrink when few products) */
#item-lookup .item-lookup-main-split.item-lookup-main-split--top {
  flex: 0 0 var(--il-top-row-height);
  height: var(--il-top-row-height);
  min-height: var(--il-top-row-height);
  max-height: var(--il-top-row-height);
  box-sizing: border-box;
  overflow-x: hidden;
  overflow-y: hidden;
  align-items: stretch;
}

@supports (overflow: clip) {
  #item-lookup .item-lookup-main-split.item-lookup-main-split--top {
    overflow-y: clip;
  }
}

#item-lookup .item-lookup-main-split--top > .item-lookup-col {
  align-self: stretch;
  min-height: 0;
}

#item-lookup .item-lookup-main-split--top .item-lookup-col--left .item-lookup-products-with-chart {
  flex: 1 1 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
}

#item-lookup .item-lookup-main-split--top .item-lookup-card--products {
  flex: 1 1 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
}

/* Individual products header toggle (e.g. LEGO "show filtered" option). */
#item-lookup .item-lookup-products-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--il-space-md);
}

#item-lookup .item-lookup-products-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 0.95rem;
  color: var(--theme-explore-muted-text);
  user-select: none;
}

#item-lookup .item-lookup-products-toggle input[type="checkbox"] {
  transform: translateY(1px);
}

#item-lookup .item-lookup-main-split--top .item-lookup-col--right > .item-lookup-card--charts-stack {
  flex: 1 1 0;
  min-height: 0;
  height: 100%;
  max-height: 100%;
}

/* Search card: market dropdown opens downward; parent tab card uses overflow:hidden elsewhere. */
#item-lookup .item-lookup-card--search-wide {
  overflow: visible;
}

#item-lookup .item-lookup-card {
  padding: var(--il-card-pad-y) var(--il-card-pad-x) calc(var(--il-card-pad-y) + 2px);
}

.item-lookup-layout {
  display: flex;
  flex-direction: column;
  gap: var(--il-stack-gap);
  margin-top: var(--il-space-md);
  width: 100%;
  max-width: 100%;
  min-width: 0;
  margin-left: auto;
  margin-right: auto;
  box-sizing: border-box;
}

.item-lookup-results-wrap:not([hidden]) {
  display: flex;
  flex-direction: column;
  gap: var(--il-stack-gap);
}

.item-lookup-card--search-wide {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.item-lookup-toolbar--wide {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  align-items: flex-end;
}

.item-lookup-field-grow--cat {
  flex: 1 1 140px;
  min-width: 0;
  max-width: 100%;
}

.item-lookup-field-grow--q {
  flex: 2 1 180px;
  min-width: 0;
  max-width: 100%;
}

.item-lookup-main-split {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: var(--il-stack-gap);
}

.item-lookup-results-primary {
  width: 100%;
  min-width: 0;
  flex: 0 0 auto;
}

.item-lookup-product-median-row {
  width: 100%;
  min-width: 0;
  flex: 0 1 auto;
}

/* No reserved space until a product is selected (shell is [hidden]). */
#item-lookup .item-lookup-product-median-row:has(#itemLookupProductChartShell[hidden]) {
  display: none;
}

.item-lookup-col {
  min-width: 0;
}

/* Equal 50/50 columns (flex gap distributes remaining space) */
.item-lookup-col--left,
.item-lookup-col--right {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.item-lookup-col--left .item-lookup-products-with-chart,
.item-lookup-col--right > .item-lookup-card {
  flex: 1 1 auto;
  min-height: 0;
}

@media (max-width: 900px) {
  .item-lookup-main-split {
    flex-wrap: wrap;
    flex-direction: column;
  }

  .item-lookup-col--left,
  .item-lookup-col--right {
    flex: 1 1 auto;
    width: 100%;
    max-width: 100%;
  }

  #item-lookup .item-lookup-main-split.item-lookup-main-split--top {
    flex: 0 0 auto;
    height: auto;
    min-height: 0;
    max-height: none;
    overflow: visible;
  }

  #item-lookup .item-lookup-main-split--top > .item-lookup-col--left,
  #item-lookup .item-lookup-main-split--top > .item-lookup-col--right {
    flex: 0 0 var(--il-top-row-pane-stacked-height);
    min-height: var(--il-top-row-pane-stacked-height);
    max-height: var(--il-top-row-pane-stacked-height);
    height: var(--il-top-row-pane-stacked-height);
    box-sizing: border-box;
    overflow: hidden;
  }

  #item-lookup .item-lookup-main-split--top .item-lookup-card--products {
    height: 100%;
    max-height: 100%;
  }

  #item-lookup .item-lookup-main-split--top .item-lookup-col--right > .item-lookup-card--charts-stack {
    height: 100%;
    max-height: 100%;
  }
}

/* Card chrome: shared with Product Analysis via components.css (#item-lookup .item-lookup-card) */

.item-lookup-card-title {
  margin: 0 0 var(--il-inner-gap);
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--theme-text-muted);
}

.item-lookup-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--il-space-md);
  align-items: flex-end;
  background: var(--theme-bg-analysis-toolbar);
  padding: var(--il-space-md) var(--il-space-lg);
  border-radius: var(--theme-tab-surface-radius, 12px);
}

#item-lookup .item-lookup-toolbar--wide > .selector-group {
  min-width: 0;
}

#item-lookup .item-lookup-toolbar--wide .item-lookup-search-actions {
  flex: 1 1 100%;
  max-width: 100%;
  justify-content: flex-start;
}

@media (min-width: 960px) {
  #item-lookup .item-lookup-toolbar--wide .item-lookup-search-actions {
    flex: 0 1 auto;
    max-width: min(100%, 420px);
  }
}

.item-lookup-toolbar .selector-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--theme-text-muted);
}

.item-lookup-field-grow {
  flex: 1 1 200px;
  min-width: 180px;
}

.item-lookup-query-input {
  width: 100%;
}

.item-lookup-search-actions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  align-self: flex-end;
  gap: 10px;
}

/* Search row: single chevron (no .analysis-dropdown on container), match modal inputs + button height */
#item-lookup .item-lookup-toolbar--wide {
  gap: var(--il-space-md) var(--il-space-lg);
}

#item-lookup .item-lookup-toolbar--wide .item-lookup-market-field .item-lookup-market-dropdown {
  width: 100%;
}

#item-lookup .item-lookup-toolbar--wide .item-lookup-scope-select {
  width: 100%;
  box-sizing: border-box;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.95rem;
  line-height: 1.35;
  background-color: var(--theme-bg-modal-input);
  border: 1px solid var(--theme-border-modal-input);
  color: var(--theme-text-modal-input);
  cursor: pointer;
}

#item-lookup .item-lookup-scope-select:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

#item-lookup .item-lookup-scope-hint {
  margin: 6px 0 0;
  font-size: 0.72rem;
  line-height: 1.35;
  color: var(--theme-text-muted);
  font-weight: 400;
  text-transform: none;
  letter-spacing: normal;
}

#item-lookup .item-lookup-toolbar--wide .item-lookup-market-field .custom-dropdown-btn {
  width: 100%;
  box-sizing: border-box;
  min-height: 44px;
  height: auto;
  padding: 11px 42px 11px 14px;
  border-radius: 8px;
  font-size: 0.95rem;
  line-height: 1.35;
  background-color: var(--theme-bg-modal-input);
  border: 1px solid var(--theme-border-modal-input);
  color: var(--theme-text-modal-input);
  transition: border-color 0.2s, box-shadow 0.2s;
}

#item-lookup .item-lookup-toolbar--wide .item-lookup-market-field .custom-dropdown-btn:hover {
  border-color: var(--theme-accent-primary);
}

#item-lookup .item-lookup-toolbar--wide .item-lookup-market-field .custom-dropdown-container:focus-within .custom-dropdown-btn {
  outline: none;
  border-color: var(--theme-accent-primary);
  box-shadow: var(--theme-shadow-input-focus);
}

#item-lookup .item-lookup-toolbar--wide .item-lookup-market-field .custom-dropdown-btn::after {
  right: 14px;
}

#item-lookup .item-lookup-toolbar--wide .item-lookup-market-field .custom-dropdown-list {
  margin-top: 6px;
  border-radius: 8px;
}

#item-lookup .item-lookup-toolbar--wide .item-lookup-query-input {
  min-height: 44px;
  box-sizing: border-box;
  border-radius: 8px;
}

#item-lookup .item-lookup-toolbar--wide .item-lookup-search-actions .action-btn {
  height: 44px;
  min-height: 44px;
  padding-left: 20px;
  padding-right: 20px;
  border-radius: 8px;
}

.item-lookup-btn--track {
  white-space: nowrap;
}

.item-lookup-chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--il-space-sm) var(--il-space-md);
  margin-bottom: var(--il-inner-gap);
}

.item-lookup-chart-toolbar__title {
  margin: 0;
  flex: 1 1 200px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--theme-text-muted);
}

.item-lookup-chart-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 0.85rem;
}

.item-lookup-card--charts-stack .time-range-selector button {
  padding: 0.35rem 0.55rem;
  font-size: 0.72rem;
}

.item-lookup-products-with-chart {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--il-stack-gap);
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
}

.item-lookup-products-with-chart > .item-lookup-card--products {
  width: 100%;
  min-width: 0;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: hidden;
}

@supports (overflow: clip) {
  .item-lookup-products-with-chart > .item-lookup-card--products {
    overflow-y: clip;
  }
}

/* Title stays fixed; grid grows; pager stays pinned to the bottom of the card */
.item-lookup-products-with-chart > .item-lookup-card--products > .item-lookup-card-title {
  flex-shrink: 0;
}

.item-lookup-products-scope-hint {
  flex-shrink: 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--text-secondary, #8a8a8a);
  margin: 0 0 0.5rem 0;
  max-width: 52ch;
}

.item-lookup-products-scope-hint code {
  font-size: 0.85em;
  padding: 0 0.2em;
  background: var(--item-lookup-surface-elevated, rgba(255, 255, 255, 0.04));
  border-radius: 3px;
}

/* Row height = max of cards in that row (auto tracks, not 1fr); short lists don’t get giant rows;
   each card in the row still stretches to that height so a one-line title lines up with a two-line. */
.item-lookup-products-with-chart > .item-lookup-card--products .item-lookup-products-grid {
  flex: 1 1 0;
  width: 100%;
  min-height: 0;
  height: 100%;
  align-content: start;
  align-items: stretch;
  grid-auto-rows: auto;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.item-lookup-products-with-chart
  > .item-lookup-card--products
  .item-lookup-products-grid
  > .item-lookup-product-card {
  height: 100%;
  min-height: 0;
  align-self: stretch;
  overflow: hidden;
}

.item-lookup-products-with-chart > .item-lookup-card--products .item-lookup-pager {
  flex-shrink: 0;
}

.item-lookup-product-chart-shell--below {
  width: 100%;
  min-width: 0;
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}

.item-lookup-product-chart-shell--below.item-lookup-product-chart-shell--active {
  border-color: var(--theme-accent-a45);
  box-shadow: 0 0 0 1px var(--theme-accent-a15);
}

.item-lookup-results-wrap[hidden] {
  display: none !important;
}

.item-lookup-product-chart-shell__head {
  margin-bottom: var(--il-inner-gap);
}

.item-lookup-product-chart-shell__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--il-space-sm);
  margin: var(--il-inner-gap) 0 var(--il-space-sm);
}

.item-lookup-add-coll-hint {
  margin: 0 0 8px;
  font-size: 0.9rem;
  font-weight: 650;
  line-height: 1.4;
  color: var(--theme-text-primary, #e5e7eb);
}

.item-lookup-add-coll-note {
  margin: 0 0 14px;
  font-size: 0.8rem;
  line-height: 1.45;
  color: var(--theme-text-muted, #8892b0);
}

.item-lookup-add-coll-error {
  margin: 10px 0 0;
  font-size: 0.85rem;
  color: #f87171;
}

body.light-mode .item-lookup-add-coll-error {
  color: #b91c1c;
}

.item-lookup-product-chart-shell__title {
  margin: 0;
}

.item-lookup-product-detail__block {
  margin-bottom: var(--il-inner-gap);
}

.item-lookup-product-detail__block::after {
  content: "";
  display: table;
  clear: both;
}

.item-lookup-product-detail__spread {
  margin: 0 0 0.5rem;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--theme-text-secondary, #111827);
}

.item-lookup-product-detail__chart-clearfix {
  clear: both;
  height: 0;
  overflow: hidden;
}

.item-lookup-product-detail__image-wrap--below {
  float: right;
  width: 100%;
  max-width: 220px;
  height: 180px;
  margin: 0 0 0.75rem 1rem;
}

button.item-lookup-product-detail__image-wrap,
button.item-lookup-product-detail__image-btn {
  cursor: zoom-in;
  border: none;
  background: transparent;
  padding: 0;
  font: inherit;
  color: inherit;
  display: block;
  border-radius: var(--theme-tab-surface-radius, 10px);
}

button.item-lookup-product-detail__image-wrap:focus-visible {
  outline: 2px solid var(--theme-accent-primary, #3b82f6);
  outline-offset: 3px;
}

button.item-lookup-product-detail__image-wrap img {
  pointer-events: none;
  border-radius: inherit;
}

.item-lookup-cache-banner {
  margin: 0 0 var(--il-inner-gap);
  padding: var(--il-space-sm) var(--il-space-md);
  border-radius: 10px;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--theme-text-primary, #e5e7eb);
  background: rgba(234, 179, 8, 0.12);
  border: 1px solid rgba(234, 179, 8, 0.35);
}

body.light-mode .item-lookup-cache-banner {
  color: #78350f;
  background: #fffbeb;
  border-color: rgba(180, 83, 9, 0.25);
}

.item-lookup-tracked {
  margin-top: var(--il-space-xl);
  padding-top: var(--il-space-lg);
  border-top: 1px solid var(--theme-tab-surface-border);
}

.item-lookup-tracked__collapse {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  margin: 0 0 var(--il-space-md);
  padding: 0.35rem 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  text-align: left;
  color: var(--theme-text-muted, #8892b0);
  transition: background 0.15s ease, color 0.15s ease;
}

.item-lookup-tracked__collapse:hover {
  color: var(--theme-text-primary, #e5e7eb);
  background: rgba(255, 255, 255, 0.04);
}

body.light-mode .item-lookup-tracked__collapse:hover {
  color: #0f172a;
  background: rgba(0, 0, 0, 0.04);
}

.item-lookup-tracked__chevron {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  margin-top: -0.2rem;
  flex-shrink: 0;
  opacity: 0.85;
  transition: transform 0.2s ease;
}

.item-lookup-tracked.is-collapsed .item-lookup-tracked__chevron {
  transform: rotate(45deg);
  margin-top: 0.1rem;
}

.item-lookup-tracked.is-collapsed .item-lookup-tracked__body {
  display: none;
}

.item-lookup-tracked__title {
  font-size: 0.8125rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.item-lookup-tracked__body {
  display: flex;
  flex-direction: column;
  gap: var(--il-space-md);
}

.item-lookup-tracked__help {
  margin: 0.35rem 0 0.65rem;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--theme-text-muted, #8892b0);
  max-width: 44rem;
}

body.light-mode .item-lookup-tracked__help {
  color: #111827;
}

.item-lookup-track-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--il-space-sm) var(--il-space-md);
  margin-bottom: 0;
  padding: var(--il-space-md) var(--il-inner-gap);
  border-radius: var(--theme-tab-surface-radius, 12px);
  border: 1px solid var(--theme-border-muted);
  background: var(--theme-bg-analysis-toolbar);
}

.item-lookup-track-panel__label {
  display: block;
  width: 100%;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--theme-text-muted, #8892b0);
  margin-bottom: 4px;
}

.item-lookup-track-panel__input {
  flex: 1;
  min-width: 180px;
}

.item-lookup-track-panel__actions {
  display: flex;
  gap: 0.5rem;
}

.item-lookup-tracked-list {
  display: flex;
  flex-wrap: wrap;
  gap: var(--il-space-sm);
  align-items: center;
}

.item-lookup-track-message {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--theme-danger, #f25f5c);
}

.item-lookup-track-message[hidden] {
  display: none !important;
}

.item-lookup-tracked-row {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.item-lookup-tracked-remove {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--theme-text-muted, #8892b0);
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
}

.item-lookup-tracked-remove:hover {
  color: var(--theme-text-primary, #e5e7eb);
  background: rgba(255, 255, 255, 0.06);
}

body.light-mode .item-lookup-tracked-remove:hover {
  color: #0f172a;
  background: rgba(0, 0, 0, 0.06);
}

.item-lookup-tracked-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 6px 8px 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--theme-border-default, rgba(255, 255, 255, 0.14));
  background: var(--theme-bg-metric, rgba(0, 0, 0, 0.22));
  color: var(--theme-text-primary, #e5e7eb);
  font-size: 0.8125rem;
  cursor: pointer;
  text-align: left;
}

body.light-mode .item-lookup-tracked-chip {
  border-color: rgba(0, 0, 0, 0.1);
  background: #fff;
  color: #0f172a;
}

.item-lookup-tracked-chip__icon {
  flex-shrink: 0;
  opacity: 0.85;
  font-size: 0.9rem;
  line-height: 1;
}

.item-lookup-tracked-chip__label {
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 10rem;
}

.item-lookup-tracked-chip__kw {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--theme-text-muted, #8892b0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 8rem;
}

body.light-mode .item-lookup-tracked-chip__kw {
  color: #111827;
}

.item-lookup-tracked-chip__x {
  flex-shrink: 0;
  margin-left: 2px;
  padding: 0 4px;
  font-size: 1.1rem;
  line-height: 1;
  opacity: 0.65;
  border-radius: 4px;
}

.item-lookup-tracked-chip__x:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.08);
}

body.light-mode .item-lookup-tracked-chip__x:hover {
  background: rgba(0, 0, 0, 0.06);
}

.item-lookup-loading {
  display: none;
  align-items: center;
  gap: 10px;
  color: var(--theme-text-muted, #8892b0);
  font-size: 0.875rem;
}

/* Below Search + Track Items; `.item-lookup-layout` flex gap handles vertical spacing. */
#item-lookup .item-lookup-loading--below-search {
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: var(--il-space-md) var(--il-card-pad-x);
  justify-content: center;
  border-radius: var(--theme-tab-surface-radius, 12px);
  background: var(--theme-roi-condensed-bg, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--theme-roi-condensed-border, rgba(255, 255, 255, 0.08));
}

.item-lookup-error {
  color: var(--theme-danger, #f25f5c);
  font-size: 0.875rem;
  min-height: 1.25rem;
  margin: 0.75rem 0 0;
}

.item-lookup-no-results {
  color: var(--theme-text-muted, #8892b0);
  font-size: 0.9rem;
  line-height: 1.45;
  margin: 0.75rem 0 0;
  padding: 0.65rem 0.85rem;
  border-radius: var(--theme-tab-surface-radius, 10px);
  background: var(--theme-roi-condensed-bg, rgba(255, 255, 255, 0.05));
  border: 1px solid var(--theme-roi-condensed-border, rgba(255, 255, 255, 0.08));
  text-align: center;
}

.item-lookup-no-results[hidden] {
  display: none !important;
}

.item-lookup-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  gap: var(--il-inner-gap);
  margin-bottom: var(--il-inner-gap);
  padding: var(--il-inner-gap) var(--il-space-md);
  border-radius: var(--theme-tab-surface-radius, 12px);
  background: var(--theme-roi-condensed-bg);
  border: 1px solid var(--theme-roi-condensed-border);
}

.item-lookup-kpis:empty {
  display: none;
  margin: 0;
  padding: 0;
  border: none;
}

.item-lookup-kpi {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  text-align: center;
}

.item-lookup-kpi-value {
  display: block;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--theme-roi-value);
  line-height: 1.2;
}

.item-lookup-kpi-value--range {
  font-size: 1.05rem;
  font-weight: 650;
  line-height: 1.3;
}

.item-lookup-kpi-label {
  display: block;
  margin-top: 4px;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--theme-roi-label);
}

.item-lookup-kpi--muted {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.item-lookup-kpi--muted .item-lookup-kpi-label {
  margin-top: 0;
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.8125rem;
  font-weight: 600;
}

.item-lookup-canonical-clusters {
  margin-top: 0;
}

.item-lookup-canonical-clusters__header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--il-space-md);
  margin-bottom: var(--il-inner-gap);
}

.item-lookup-canonical-clusters__title {
  margin: 0 0 var(--il-space-xs);
  font-size: 1rem;
  font-weight: 700;
  color: var(--theme-text-primary, #e5e7eb);
}

body.light-mode .item-lookup-canonical-clusters__title {
  color: #0f172a;
}

.item-lookup-canonical-clusters__lead {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--theme-text-muted, #8892b0);
}

.item-lookup-canonical-clusters__actions {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  flex-shrink: 0;
}

.item-lookup-canonical-clusters__meta {
  margin: 0 0 var(--il-inner-gap);
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--theme-text-muted, #8892b0);
}

.item-lookup-canonical-clusters__body[hidden] {
  display: none !important;
}

.item-lookup-canonical-clusters__lead code {
  font-size: 0.78em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--theme-bg-analysis-toolbar);
  border: 1px solid var(--theme-border-muted);
}

.item-lookup-canonical-clusters-list {
  display: flex;
  flex-direction: column;
  gap: var(--il-inner-gap);
}

.item-lookup-canonical-cluster {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--il-space-sm) var(--il-space-md);
  align-items: start;
  padding: var(--il-space-sm) var(--il-space-md);
  border-radius: 8px;
  border: 1px solid var(--theme-border-muted);
  background: var(--theme-bg-analysis-toolbar);
}

body.light-mode .item-lookup-canonical-cluster {
  background: var(--theme-bg-analysis-toolbar);
}

.item-lookup-canonical-cluster--unparsed {
  opacity: 0.92;
}

.item-lookup-canonical-cluster__label {
  display: block;
  font-size: 0.9rem;
  font-weight: 650;
  line-height: 1.35;
  color: var(--theme-text-primary, #e5e7eb);
}

body.light-mode .item-lookup-canonical-cluster__label {
  color: #111827;
}

.item-lookup-canonical-cluster__stats {
  display: block;
  margin-top: 4px;
  font-size: 0.8125rem;
  color: var(--theme-text-muted, #8892b0);
}

.item-lookup-canonical-cluster__sample {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--theme-text-muted, #8892b0);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.item-lookup-canonical-cluster__actions {
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
}

.item-lookup-canonical-cluster__no-product {
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--theme-text-muted, #8892b0);
  text-align: right;
  max-width: 200px;
}

.item-lookup-matches {
  margin-top: 0;
  padding-top: var(--il-space-lg);
  border-top: 1px solid var(--theme-tab-surface-border);
}

.item-lookup-matches-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--il-space-md);
  margin-bottom: var(--il-inner-gap);
}

.item-lookup-matches-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--theme-text-primary, #e5e7eb);
}

body.light-mode .item-lookup-matches-title {
  color: #0f172a;
}

.item-lookup-matches-meta {
  margin: 0.35rem 0 0;
  font-size: 0.8125rem;
  line-height: 1.45;
  color: var(--theme-text-muted, #8892b0);
}

.item-lookup-matches-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  flex-shrink: 0;
}

.item-lookup-matches-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--il-inner-gap);
}

.item-lookup-match {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--il-space-sm);
  padding: var(--il-space-sm) var(--il-space-md);
  border-radius: 8px;
  border: 1px solid var(--theme-border-muted);
  background: var(--theme-bg-analysis-toolbar);
}

body.light-mode .item-lookup-match {
  background: var(--theme-bg-analysis-toolbar);
}

a.item-lookup-match--row-link {
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  transition:
    border-color 0.12s ease,
    background 0.12s ease;
}

a.item-lookup-match--row-link:hover {
  border-color: var(--theme-accent-a40, rgba(75, 156, 211, 0.4));
  background: var(--theme-accent-a08, rgba(75, 156, 211, 0.1));
}

a.item-lookup-match--row-link:focus-visible {
  outline: 2px solid var(--theme-accent-primary, #3b82f6);
  outline-offset: 2px;
}

body.light-mode a.item-lookup-match--row-link:hover {
  background: var(--theme-accent-a10, rgba(37, 99, 235, 0.1));
}

/* eBay mark when the whole row is the link (avoids nested <a>) */
.item-lookup-match__ebay-ico {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  align-self: center;
  flex-shrink: 0;
  padding: 8px 12px;
  min-height: 38px;
  min-width: 64px;
  line-height: 0;
  border-radius: 8px;
  border: 1px solid var(--theme-border-default, rgba(255, 255, 255, 0.12));
  background: var(--theme-bg-btn-secondary, rgba(255, 255, 255, 0.06));
  box-sizing: border-box;
}

body.light-mode .item-lookup-match__ebay-ico {
  border-color: rgba(0, 0, 0, 0.12);
  background: #f1f5f9;
}

.item-lookup-match-thumb {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--theme-border-muted);
  display: grid;
  place-items: center;
}

body.light-mode .item-lookup-match-thumb {
  background: rgba(0, 0, 0, 0.04);
}

.item-lookup-match-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.item-lookup-match-thumb--empty {
  opacity: 0.5;
}

.item-lookup-match-text {
  min-width: 0;
  flex: 1;
}

.item-lookup-match-title {
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--theme-text-primary, #e5e7eb);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

body.light-mode .item-lookup-match-title {
  color: #111827;
}

.item-lookup-match-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.8125rem;
  color: var(--theme-text-primary, #e5e7eb);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.light-mode .item-lookup-match-id {
  color: #111827;
}

.item-lookup-match-actions {
  display: inline-flex;
  gap: 6px;
  flex-shrink: 0;
}

.item-lookup-match-actions button,
.item-lookup-match-actions a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--theme-border-default, rgba(255, 255, 255, 0.12));
  background: var(--theme-bg-btn-secondary, rgba(255, 255, 255, 0.06));
  color: var(--theme-text-primary, #e5e7eb);
  text-decoration: none;
  cursor: pointer;
}

body.light-mode .item-lookup-match-actions button,
body.light-mode .item-lookup-match-actions a {
  border-color: rgba(0, 0, 0, 0.12);
  background: #f1f5f9;
  color: #0f172a;
}

.item-lookup-chart-wrap {
  position: relative;
  margin-top: var(--il-space-xs);
}

/* Right column charts: grow with column height (Chart.js responsive + ResizeObserver). */
#item-lookup .item-lookup-card--charts-stack {
  flex: 1 1 auto;
  min-height: 0;
  align-self: stretch;
  display: flex;
  flex-direction: column;
}

#item-lookup .item-lookup-card--charts-stack > .item-lookup-chart-wrap--cohort-trend {
  flex: 1 1 0;
  min-height: var(--il-chart-min);
  display: flex;
  flex-direction: column;
}

#item-lookup .item-lookup-card--charts-stack > .item-lookup-chart-wrap--cohort-trend .chart-container {
  flex: 1 1 auto;
  min-height: var(--il-chart-min);
  height: auto !important;
  max-height: none;
  width: 100%;
  margin-bottom: 0;
  padding: var(--il-space-sm) var(--il-space-md);
  background: var(--theme-bg-analysis-toolbar);
  border: 1px solid var(--theme-border-muted);
  border-radius: 8px;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}

/* Product median chart — full-width row below cohort + products */
#item-lookup .item-lookup-product-chart-shell .item-lookup-chart-wrap--product {
  flex: 1 1 auto;
  min-height: var(--il-product-chart-min);
  display: flex;
  flex-direction: column;
}

#item-lookup .item-lookup-product-chart-shell .item-lookup-chart-wrap--product .chart-container {
  flex: 1 1 auto;
  min-height: var(--il-product-chart-min);
  height: auto !important;
  max-height: min(420px, 52vh);
  margin-bottom: 0;
  padding: var(--il-space-sm) var(--il-space-md);
  background: var(--theme-bg-analysis-toolbar);
  border: 1px solid var(--theme-border-muted);
  border-radius: 8px;
  box-shadow: none;
  box-sizing: border-box;
}

#item-lookup .item-lookup-product-chart-shell--fullwidth {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

#item-lookup .item-lookup-product-chart-shell--fullwidth .item-lookup-chart-wrap--product {
  min-height: clamp(200px, 22vh, 360px);
  max-height: min(480px, 56vh);
}

#item-lookup .item-lookup-product-chart-shell--fullwidth .item-lookup-chart-wrap--product .chart-container {
  min-height: clamp(180px, 20vh, 420px);
}

.item-lookup-chart-canvas {
  min-height: 0;
}

.item-lookup-empty--inline {
  padding: 1rem 0.75rem;
  text-align: left;
}

.item-lookup-disclaimer {
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--theme-text-muted, #8892b0);
  margin: var(--il-space-lg) 0 0;
  max-width: 48rem;
}

body.light-mode .item-lookup-disclaimer {
  color: #111827;
}

.item-lookup-empty {
  text-align: center;
  padding: 2.5rem 1.25rem;
  color: var(--theme-text-muted, #8892b0);
  font-size: 0.9375rem;
  line-height: 1.5;
}

/* Full list modal */
.item-lookup-modal {
  position: fixed;
  inset: 0;
  z-index: 12000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  box-sizing: border-box;
}

.item-lookup-modal:not(.is-open) {
  display: none !important;
  pointer-events: none;
}

.item-lookup-modal.is-open {
  display: flex !important;
  pointer-events: auto;
}

.item-lookup-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(2px);
}

.item-lookup-modal__panel {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 720px;
  max-height: min(85vh, 640px);
  display: flex;
  flex-direction: column;
  border-radius: var(--theme-tab-surface-radius, 12px);
  border: 1px solid var(--theme-tab-surface-border);
  background: var(--theme-tab-surface-bg);
  box-shadow: var(--theme-tab-surface-shadow), 0 24px 48px rgba(0, 0, 0, 0.35);
}

/* Product image: full-viewport, no card frame or inner padding (backdrop only) */
.item-lookup-product-image-lightbox.item-lookup-modal {
  padding: 0;
}

.item-lookup-product-image-lightbox .item-lookup-product-image-lightbox__panel {
  position: relative;
  z-index: 1;
  /* Fill viewport so the <img> can use object-fit: contain and upscale small thumb bitmaps */
  width: 100vw;
  max-width: 100vw;
  height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  padding: 0;
  display: flex;
  align-items: stretch;
  justify-content: center;
  box-sizing: border-box;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.item-lookup-product-image-lightbox__img {
  display: block;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  /* Layout box = viewport: replaces intrinsic s-l* pixel size so the image scales up */
  width: 100%;
  max-width: 100vw;
  height: 100%;
  max-height: calc(100vh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  max-height: calc(100dvh - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  object-fit: contain;
  object-position: center;
  border-radius: 0;
  background: transparent;
}

.item-lookup-product-image-lightbox__close {
  position: fixed;
  top: max(12px, env(safe-area-inset-top, 0px));
  right: max(12px, env(safe-area-inset-right, 0px));
  z-index: 12002;
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.85));
}

.item-lookup-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 14px 18px;
  border-bottom: 1px solid var(--theme-tab-surface-border);
}

.item-lookup-modal__title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--theme-text-primary, #f1f5f9);
}

body.light-mode .item-lookup-modal__title {
  color: #0f172a;
}

.item-lookup-modal__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 10px 18px;
  border-bottom: 1px solid var(--theme-tab-surface-border);
}

.item-lookup-modal__count {
  margin: 0;
  font-size: 0.875rem;
  color: var(--theme-text-muted, #8892b0);
}

.item-lookup-modal__pager {
  flex-shrink: 0;
  padding: 10px 18px;
  border-bottom: 1px solid var(--theme-tab-surface-border);
}

.item-lookup-modal__pager:empty {
  display: none;
  padding: 0;
  border-bottom: none;
}

.item-lookup-pager {
  margin-top: var(--il-inner-gap);
  padding-top: var(--il-inner-gap);
  border-top: 1px solid var(--theme-tab-surface-border);
}

.item-lookup-pager:empty {
  display: none;
  margin: 0;
  padding: 0;
  border: none;
}

.item-lookup-pager__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 0.75rem 1rem;
}

.item-lookup-pager__status {
  font-size: 0.8125rem;
  color: var(--theme-text-muted, #8892b0);
  text-align: center;
  flex: 1 1 12rem;
}

.item-lookup-pager__btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.item-lookup-modal__list {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.75rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
  -webkit-overflow-scrolling: touch;
}

.item-lookup-modal__list .item-lookup-match {
  flex-shrink: 0;
}

/* Parsed products (per-title identity) */
.item-lookup-products-lead {
  margin: 0 0 var(--il-inner-gap);
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--theme-text-muted, #8892b0);
  max-width: 46rem;
}

body.light-mode .item-lookup-products-lead {
  color: #111827;
}

.item-lookup-products-empty {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--theme-text-muted, #8892b0);
  max-width: 42rem;
}

body.light-mode .item-lookup-products-empty {
  color: #111827;
}

.item-lookup-products-empty--detail {
  margin-top: 10px;
  font-size: 0.8125rem;
  line-height: 1.45;
}

/* Product cards: top row left pane (~half the viewport). At most two columns. */
.item-lookup-products-grid {
  display: grid;
  gap: var(--il-inner-gap);
  grid-template-columns: 1fr;
  /* Default: content-sized rows (e.g. empty state). "With chart" pane overrides to 1fr rows. */
  align-content: start;
  justify-content: start;
  align-items: start;
  grid-auto-rows: auto;
}

@media (min-width: 520px) {
  .item-lookup-products-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .item-lookup-product-card__thumb {
    width: 80px;
    height: 80px;
  }
}

.item-lookup-product-card {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  gap: var(--il-space-sm);
  padding: var(--il-space-sm) var(--il-inner-gap);
  border-radius: var(--theme-tab-surface-radius, 12px);
  border: 1px solid var(--theme-border-muted);
  background: var(--theme-bg-analysis-toolbar);
  color: var(--theme-text-primary, #e5e7eb);
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
}

.item-lookup-product-card--no-db {
  cursor: default;
  opacity: 0.92;
}

.item-lookup-product-card--resolvable {
  cursor: pointer;
  opacity: 1;
}

.item-lookup-product-card__thumb {
  flex-shrink: 0;
  width: 72px;
  height: 72px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--theme-bg-metric, rgba(0, 0, 0, 0.35));
  border: 1px solid var(--theme-border-default, rgba(255, 255, 255, 0.1));
}

body.light-mode .item-lookup-product-card__thumb {
  background: #f1f5f9;
  border-color: rgba(0, 0, 0, 0.08);
}

.item-lookup-product-card__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.item-lookup-product-card__thumb--empty {
  background: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 4px,
    rgba(255, 255, 255, 0.04) 4px,
    rgba(255, 255, 255, 0.04) 8px
  );
}

body.light-mode .item-lookup-product-card__thumb--empty {
  background: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 4px,
    rgba(0, 0, 0, 0.04) 4px,
    rgba(0, 0, 0, 0.04) 8px
  );
}

.item-lookup-product-card__main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  min-width: 0;
  min-height: 0;
  flex: 1 1 0;
  overflow: hidden;
}

.item-lookup-product-card:hover {
  border-color: var(--theme-accent-a40);
  background: var(--theme-accent-a08);
}

body.light-mode .item-lookup-product-card {
  background: var(--theme-bg-analysis-toolbar);
  color: #0f172a;
}

body.light-mode .item-lookup-product-card:hover {
  border-color: var(--theme-accent-a45);
  background: var(--theme-accent-a10);
}

.item-lookup-product-card.is-active {
  border-color: var(--theme-accent-primary);
  background: var(--theme-accent-a12);
  box-shadow: 0 0 0 1px var(--theme-accent-a25);
}

body.light-mode .item-lookup-product-card.is-active {
  background: var(--theme-accent-a10);
  box-shadow: 0 0 0 1px var(--theme-accent-a30);
}

.item-lookup-product-card__icon {
  font-size: 0.85rem;
  opacity: 0.8;
}

.item-lookup-product-card__title {
  font-size: 0.9375rem;
  font-weight: 650;
  line-height: 1.35;
  align-self: stretch;
  min-height: 0;
  flex: 0 1 auto;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.item-lookup-product-card__meta {
  font-size: 0.75rem;
  line-height: 1.35;
  color: var(--theme-text-muted, #8892b0);
  align-self: stretch;
  flex: 0 1 auto;
  min-height: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow-wrap: anywhere;
  word-break: break-word;
}

body.light-mode .item-lookup-product-card__meta {
  color: #111827;
}

.item-lookup-product-card__stats {
  display: flex;
  flex-direction: column;
  gap: 2px;
  /* Pin median/history to the bottom when the card is stretched to a taller row-sibling. */
  margin-top: auto;
  min-height: 0;
  flex: 0 1 auto;
  align-self: stretch;
  overflow: hidden;
}

.item-lookup-product-card__stat {
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--theme-accent-primary, #4b9cd3);
  overflow: hidden;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.item-lookup-product-card__stat--history {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--theme-text-muted, #8892b0);
}

body.light-mode .item-lookup-product-card__stat--history {
  color: #111827;
}

.item-lookup-product-card__spread {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  margin-top: 4px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--theme-text-muted, #8892b0);
  overflow: hidden;
  overflow-wrap: anywhere;
  word-break: break-word;
}

body.light-mode .item-lookup-product-card__spread {
  color: #111827;
}

.item-lookup-product-detail {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--theme-border-card, rgba(255, 255, 255, 0.08));
}

body.light-mode .item-lookup-product-detail {
  border-top-color: rgba(0, 0, 0, 0.08);
}

.item-lookup-product-detail__image-wrap {
  float: right;
  width: 112px;
  height: 112px;
  margin: 0 0 0.75rem 1rem;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--theme-border-default, rgba(255, 255, 255, 0.12));
  background: var(--theme-bg-metric, rgba(0, 0, 0, 0.25));
}

body.light-mode .item-lookup-product-detail__image-wrap {
  border-color: rgba(0, 0, 0, 0.1);
  background: #f8fafc;
}

.item-lookup-product-detail__image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.item-lookup-product-chart-shell:not(.item-lookup-product-chart-shell--below)::after {
  content: "";
  display: table;
  clear: both;
}

.item-lookup-product-detail__title {
  margin: 0 0 0.25rem;
  font-size: 1.05rem;
  font-weight: 650;
}

.item-lookup-product-detail__meta {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  color: var(--theme-text-muted, #8892b0);
}

.item-lookup-product-active-indicator {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.45;
  color: var(--theme-accent-muted);
  background: var(--theme-accent-a10);
  border: 1px solid var(--theme-accent-a35);
}

body.light-mode .item-lookup-product-active-indicator {
  color: var(--theme-accent-hover);
  background: var(--theme-accent-a10);
  border-color: var(--theme-accent-a35);
}

.item-lookup-product-active-indicator__dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  margin-top: 0.35em;
  border-radius: 50%;
  background: var(--theme-accent-primary);
  box-shadow: 0 0 0 0 var(--theme-accent-a45);
  animation: item-lookup-active-pulse 2s ease-out infinite;
}

@keyframes item-lookup-active-pulse {
  0% {
    box-shadow: 0 0 0 0 var(--theme-accent-a45);
  }
  70% {
    box-shadow: 0 0 0 8px transparent;
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

.item-lookup-product-active-indicator__text {
  min-width: 0;
}

.item-lookup-product-active-indicator--below-title {
  display: inline-flex;
  align-items: flex-start;
  gap: 0.45rem;
  max-width: 100%;
  margin: 0 0 0.5rem;
  padding: 6px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.35;
  text-align: left;
  justify-content: flex-start;
}

.item-lookup-product-active-indicator--below-title .item-lookup-product-active-indicator__dot {
  margin-top: 0.28em;
}

.item-lookup-chart-wrap--product {
  min-height: var(--il-product-chart-min, 220px);
}

.item-lookup-chart-canvas--product {
  min-height: 0;
}

/* Product detail: sample listings (single-item observations) */
.item-lookup-product-listings {
  margin-top: var(--il-inner-gap);
  padding-top: var(--il-inner-gap);
  border-top: 1px solid var(--theme-tab-surface-border);
}

.item-lookup-product-listings__head {
  margin-bottom: var(--il-space-sm);
}

.item-lookup-product-listings__title {
  margin: 0 0 6px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--theme-text-muted);
}

.item-lookup-product-listings__hint {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--theme-text-muted, #8892b0);
}

body.light-mode .item-lookup-product-listings__hint {
  color: #111827;
}

.item-lookup-product-listings__list {
  display: flex;
  flex-direction: column;
  gap: var(--il-space-sm);
  max-height: min(320px, 42vh);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 2px;
}

.item-lookup-product-listing {
  display: flex;
  align-items: center;
  gap: var(--il-space-sm);
  padding: var(--il-space-sm) var(--il-inner-gap);
  border-radius: 8px;
  border: 1px solid var(--theme-border-muted);
  background: var(--theme-bg-analysis-toolbar);
  min-width: 0;
}

.item-lookup-product-listing__thumb {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  overflow: hidden;
  background: var(--theme-bg-metric, rgba(0, 0, 0, 0.2));
  border: 1px solid var(--theme-border-muted);
}

.item-lookup-product-listing__thumb--empty {
  background: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 4px,
    rgba(255, 255, 255, 0.04) 4px,
    rgba(255, 255, 255, 0.04) 8px
  );
}

body.light-mode .item-lookup-product-listing__thumb--empty {
  background: repeating-linear-gradient(
    -45deg,
    transparent,
    transparent 4px,
    rgba(0, 0, 0, 0.04) 4px,
    rgba(0, 0, 0, 0.04) 8px
  );
}

.item-lookup-product-listing__thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.item-lookup-product-listing__main {
  flex: 1;
  min-width: 0;
}

.item-lookup-product-listing__title {
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--theme-text-primary, #e5e7eb);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

body.light-mode .item-lookup-product-listing__title {
  color: #0f172a;
}

.item-lookup-product-listing__price {
  font-size: 0.75rem;
  font-weight: 600;
  margin-top: 4px;
  color: var(--theme-accent-primary, #4b9cd3);
}

.item-lookup-product-listing__dom {
  font-size: 0.68rem;
  margin-top: 2px;
  color: var(--theme-text-muted, #111827);
}

body.light-mode .item-lookup-product-listing__dom {
  color: #111827;
}

.item-lookup-product-listing__actions {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  justify-content: center;
}

@media (min-width: 520px) {
  .item-lookup-product-listing__actions {
    flex-direction: row;
    align-items: center;
  }
}

.item-lookup-product-listing__actions--search {
  flex-wrap: wrap;
  max-width: 140px;
  justify-content: flex-end;
  gap: 4px;
}

.item-lookup-product-listing__stale-hint {
  font-size: 0.62rem;
  line-height: 1.2;
  text-align: center;
  color: var(--text-secondary, #9ca3af);
}

body.light-mode .item-lookup-product-listing__stale-hint {
  color: #64748b;
}

.item-lookup-product-listing__btn,
.item-lookup-product-listing__link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid var(--theme-border-default, rgba(255, 255, 255, 0.12));
  background: var(--theme-bg-btn-secondary, rgba(255, 255, 255, 0.06));
  color: var(--theme-text-primary, #e5e7eb);
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  white-space: nowrap;
  box-sizing: border-box;
  line-height: 1.2;
}

/* Logo-only control: tight box, centered in actions column + inside the chip. */
.item-lookup-product-listing__actions .item-lookup-product-listing__link--ebay,
.item-lookup-match-actions .item-lookup-product-listing__link--ebay {
  align-self: center;
  justify-content: center;
  align-items: center;
  /* Bigger tap target for "Open on eBay" */
  padding: 8px 12px;
  min-height: 38px;
  min-width: 64px;
  line-height: 0;
}

.item-lookup-ebay-open-logo {
  flex-shrink: 0;
  display: block;
  height: 22px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  object-position: center;
}

body.light-mode .item-lookup-product-listing__btn,
body.light-mode .item-lookup-product-listing__link {
  border-color: rgba(0, 0, 0, 0.12);
  background: #f1f5f9;
  color: #0f172a;
}

.item-lookup-product-listing__btn:hover,
.item-lookup-product-listing__link:hover {
  border-color: var(--theme-accent-a40);
  background: var(--theme-accent-a08);
}

body.light-mode .item-lookup-product-listing__btn:hover,
body.light-mode .item-lookup-product-listing__link:hover {
  background: var(--theme-accent-a10);
}

/* Parser / grouping confidence (matched listings, clusters, product cards, Explore comps) */
.item-lookup-conf-badge {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1.2;
  padding: 2px 6px;
  border-radius: 999px;
  border: 1px solid var(--theme-border-muted);
  background: var(--theme-accent-a08, rgba(75, 156, 211, 0.12));
  color: var(--theme-accent-primary, #4b9cd3);
  white-space: nowrap;
}

body.light-mode .item-lookup-conf-badge {
  background: var(--theme-accent-a10, rgba(37, 99, 235, 0.12));
  color: var(--theme-accent-primary, #2563eb);
}

.item-lookup-product-listing__title-row,
.item-lookup-match-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.item-lookup-product-listing__title-row .item-lookup-product-listing__title,
.item-lookup-match-title-row .item-lookup-match-title {
  flex: 1 1 120px;
  min-width: 0;
}

.item-lookup-product-card__conf {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  margin-top: 4px;
  overflow: hidden;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.item-lookup-canonical-cluster__stats .item-lookup-conf-badge {
  vertical-align: middle;
}

/* ---------------------------------------------------------------------------
   Small screens (phones) — fit Item Lookup in the viewport, avoid overflow
   --------------------------------------------------------------------------- */
@media (max-width: 767.98px) {
  #item-lookup {
    min-width: 0;
    max-width: 100%;
    overflow-x: clip;
    --il-space-xs: 6px;
    --il-space-sm: 10px;
    --il-space-md: 12px;
    --il-space-lg: 16px;
    --il-space-xl: 20px;
    --il-stack-gap: 14px;
    --il-inner-gap: 10px;
    --il-card-pad-y: 14px;
    --il-card-pad-x: 14px;
    --il-chart-min: 140px;
    --il-product-chart-min: 200px;
    /* Shorter stacked “top row” panes so the cohort + product sections don’t dominate a short screen */
    --il-top-row-pane-stacked-height: clamp(200px, 40vh, 400px);
    --il-top-row-pane-stacked-height: clamp(200px, 40dvh, 400px);
  }

  #item-lookup .market-header h2 {
    font-size: 1.35rem;
    letter-spacing: 1.5px;
    width: 100%;
    max-width: 100%;
    padding-bottom: 8px;
    margin-bottom: var(--il-space-md);
    border-bottom-width: 3px;
  }

  #item-lookup .item-lookup-card {
    max-width: 100%;
  }

  #item-lookup .item-lookup-toolbar--wide {
    flex-direction: column;
    align-items: stretch;
    padding: var(--il-space-sm) var(--il-space-md);
  }

  #item-lookup .item-lookup-field-grow--cat,
  #item-lookup .item-lookup-field-grow--q {
    flex: 1 1 auto;
    min-width: 0;
  }

  #item-lookup .item-lookup-search-actions {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px 10px;
  }

  #item-lookup .item-lookup-search-actions .action-btn,
  #item-lookup .item-lookup-toolbar--wide .item-lookup-search-actions .action-btn {
    flex: 1 1 calc(50% - 5px);
    min-width: min(100%, 7rem);
    min-height: 44px;
  }

  #item-lookup .item-lookup-btn--track {
    white-space: normal;
    line-height: 1.2;
    text-align: center;
  }

  #item-lookup .item-lookup-products-head {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 8px;
  }

  .item-lookup-matches-list {
    grid-template-columns: minmax(0, 1fr);
  }

  .item-lookup-matches-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .item-lookup-matches-actions {
    display: flex;
    flex-direction: column;
  }

  .item-lookup-matches-actions .action-btn {
    width: 100%;
  }

  .item-lookup-match,
  a.item-lookup-match--row-link {
    min-width: 0;
  }

  .item-lookup-match .item-lookup-match-text {
    min-width: 0;
  }

  .item-lookup-matches-meta {
    word-wrap: break-word;
    overflow-wrap: anywhere;
  }

  .item-lookup-kpis {
    grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
    padding-left: 10px;
    padding-right: 10px;
  }

  .item-lookup-canonical-cluster {
    grid-template-columns: 1fr;
  }

  #item-lookup .item-lookup-card--charts-stack > .item-lookup-chart-wrap--cohort-trend .chart-container,
  #item-lookup .item-lookup-product-chart-shell .item-lookup-chart-wrap--product .chart-container {
    padding-left: 10px;
    padding-right: 10px;
  }

  #item-lookup .item-lookup-product-chart-shell--fullwidth .item-lookup-chart-wrap--product {
    max-height: min(400px, 50dvh);
    min-height: clamp(180px, 28dvh, 300px);
  }

  .item-lookup-pager__inner {
    padding-left: 0;
    padding-right: 0;
  }

  .item-lookup-pager__status {
    flex: 1 1 100%;
  }

  .item-lookup-product-detail__image-wrap--below {
    float: none;
    display: block;
    width: min(220px, 88vw);
    max-width: 100%;
    height: auto;
    min-height: 0;
    aspect-ratio: 1;
    margin: 0 auto 0.75rem;
  }

  .item-lookup-product-detail__image-wrap:not(.item-lookup-product-detail__image-wrap--below) {
    float: none;
    display: block;
    width: min(200px, 50vw);
    max-width: 100%;
    height: auto;
    min-height: 0;
    aspect-ratio: 1;
    margin: 0 auto 0.75rem;
  }

  .item-lookup-product-detail__title,
  .item-lookup-product-detail__meta,
  .item-lookup-product-listings {
    min-width: 0;
  }

  .item-lookup-modal:not(.item-lookup-product-image-lightbox) {
    padding: 8px;
  }

  .item-lookup-modal__list {
    padding: 0.5rem 0.65rem 0.75rem;
  }

  .item-lookup-modal__header {
    padding: 10px 12px;
  }

  .item-lookup-modal__panel {
    max-width: 100%;
    max-height: min(92dvh, 100%);
  }

  .item-lookup-modal__toolbar {
    padding: 8px 12px;
  }
}

@media (max-width: 480px) {
  #item-lookup {
    --il-top-row-pane-stacked-height: clamp(180px, 38dvh, 360px);
  }

  #item-lookup .item-lookup-search-actions,
  .item-lookup-matches-actions {
    flex-direction: column;
  }

  #item-lookup .item-lookup-search-actions .action-btn,
  #item-lookup .item-lookup-toolbar--wide .item-lookup-search-actions .action-btn {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
  }

  .item-lookup-kpi-value {
    font-size: 1.1rem;
  }

  .item-lookup-match,
  a.item-lookup-match--row-link {
    padding: 10px 10px;
    flex-wrap: wrap;
  }
}
