/* Layout and mobile UI layer. Plain CSS so it applies without a Tailwind rebuild. */
.ui-visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.ui-actions > * { grid-column: auto !important; }
.ui-tabs { display: flex; gap: .25rem; margin: 0 0 .5rem; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); }
.ui-tab { position: relative; white-space: nowrap; flex-shrink: 0; padding: .55rem .9rem; font-size: .8rem; font-weight: 600; color: var(--muted); background: none; border: 0; cursor: pointer; }
.ui-tab[aria-selected="true"] { color: var(--ink); }
.ui-tab[aria-selected="true"]::after { content: ''; position: absolute; left: .5rem; right: .5rem; bottom: -1px; height: 2px; background: #df1830; }
.ui-tab:focus-visible { outline: 2px solid #df1830; outline-offset: -2px; }

/* Before the first search: a friendly start panel instead of an empty table and pager. */
.ui-start { display: none; padding: 2.5rem 1.75rem; text-align: center; }
.ui-start h3 { font-size: 1.05rem; font-weight: 700; margin-bottom: .35rem; }
.ui-start p { font-size: .8rem; color: var(--muted); margin-bottom: 1.1rem; }
.ui-start-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; }
.ui-button { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; border: 1px solid var(--line); border-radius: .25rem; background: var(--surface); color: var(--ink); padding: .7rem 1rem; font-size: .8rem; font-weight: 600; cursor: pointer; }
.ui-button:hover { border-color: #df1830; }
.ui-button-primary { background: #df1830; border-color: #df1830; color: #fff; }
.ui-button-primary:hover { background: #b80e25; }
body:not(.ui-searched) .ui-start { display: block; }
body:not(.ui-searched) .table-frame, body:not(.ui-searched) .ui-cards { display: none; }
.pager[data-single="true"], body:not(.ui-searched) .pager, body:not(.ui-searched) .results-footer { display: none !important; }

/* Recommendations: show that the strip scrolls. */
.ui-scroll-hint { -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); }
.ui-scroll-hint[data-end="true"] { -webkit-mask-image: none; mask-image: none; }

.ui-cards, .ui-bar, .ui-sheet-head, .ui-backdrop, .ui-filter-toggle { display: none; }
.freshness-relative { color: var(--muted); font-weight: 400; }
.ui-meta { display: flex; align-items: center; justify-content: space-between; gap: .75rem; margin-top: .5rem; border-top: 1px solid var(--line); padding-top: .5rem; }
.ui-meta #freshness { margin: 0 !important; padding: 0 !important; border: 0 !important; }
.ui-fresh { white-space: nowrap; display: inline-flex; align-items: center; gap: .4rem; font-size: .75rem; color: var(--muted); }
.ui-menu { position: relative; }
.ui-meta { flex-wrap: wrap; }
.ui-meta #freshness { margin-right: auto !important; }
.ui-segment { display: inline-flex; border: 1px solid var(--line); border-radius: 1rem; padding: 2px; }
.ui-segment button { border: 0; background: none; border-radius: 1rem; padding: .25rem .7rem; font-size: .72rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.ui-segment button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }
.ui-card-sell { display: none; }
body.ui-sell .ui-card-sell { display: block; }
body.ui-sell .ui-card-buy { display: none; }
.ui-card-sell .ui-card-price { gap: .9rem; }
.ui-card-sell small { font-size: .65rem; font-weight: 600; color: var(--muted); margin-right: .15rem; }
/* Desktop table: highlight the trade-in columns when selling. */
body.ui-sell .table-frame td:nth-child(8), body.ui-sell .table-frame td:nth-child(9) { background: color-mix(in srgb, #16a34a 8%, transparent); font-size: .85rem; }
body.ui-sell .table-frame th:nth-child(8), body.ui-sell .table-frame th:nth-child(9) { color: #15803d; }
body.ui-sell .table-frame td:nth-child(5) { font-weight: 400 !important; color: var(--muted) !important; }
.ui-menu-button { list-style: none; display: grid; place-items: center; width: 2rem; height: 2rem; border: 1px solid var(--line); border-radius: .25rem; color: var(--ink); cursor: pointer; }
.ui-menu-button::-webkit-details-marker { display: none; }
.ui-menu-button:hover { border-color: #df1830; }
.ui-menu-panel { position: absolute; right: 0; top: calc(100% + .35rem); z-index: 30; display: grid; gap: .5rem; width: min(17rem, 80vw); padding: .6rem; background: var(--surface); border: 1px solid var(--line); border-radius: .375rem; box-shadow: 0 8px 24px #0003; font-size: .75rem; }
.ui-menu-panel > * { margin: 0 !important; }
.ui-menu-panel > div { display: grid !important; gap: .4rem; }
.ui-menu-panel button { width: 100%; justify-content: flex-start !important; }

@media (hover: none) { .ui-shortcuts { display: none; } }

@media (width < 48rem) {
  body { padding-bottom: calc(4.25rem + env(safe-area-inset-bottom)); }
  /* Results first: let the sidebar's sections sit in the page flow and reorder them. */
  .catalogue-sidebar { display: contents; }
  .catalogue-intro { order: 1; padding-top: 1rem !important; padding-bottom: 1rem !important; }
  .results-shell { order: 2; min-height: 0 !important; }
  .nearby { order: 3; }
  .sidebar-footer { order: 4; }
  .catalogue-intro .eyebrow, .catalogue-intro > p:not(.eyebrow), .catalogue-intro .search-hint { display: none; }
  /* Keep the page's main heading for screen readers while hiding the hero visually. */
  .catalogue-intro h1 { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; margin: 0 !important; }
  .catalogue-intro .search-stack { margin-top: 0; grid-template-columns: 1fr auto; }
  .catalogue-intro .search-stack #q { grid-column: 1 / -1; font-size: 16px; }
  .catalogue-intro .search-stack .primary-action { grid-column: 1; }
  .catalogue-intro .search-stack > button[onclick*="BarcodeScanner"] { display: none; }
  .ui-filter-toggle { display: inline-flex; grid-column: 2; }
  .ui-filter-count { min-width: 1.25rem; height: 1.25rem; border-radius: 1rem; background: #df1830; color: #fff; font-size: .7rem; line-height: 1.25rem; text-align: center; }
  .ui-filter-count:empty { display: none; }

  /* Recommendations move below the results. */
  .results-shell > section:first-child { order: 5; border-top: 1px solid var(--line); }
  .results-header { order: 1; padding-top: 1rem !important; }
  .results-header .eyebrow { display: none; }
  .table-frame { order: 2; }
  .ui-start, .ui-cards { order: 2; }
  .pager { order: 3; }
  .results-footer { display: none; }

  /* Cards instead of the wide table. */
  .table-frame { display: none !important; }
  body.ui-searched .ui-cards { display: block; }
  .ui-card { display: grid; grid-template-columns: 4rem 1fr; gap: .8rem; padding: .9rem 1.25rem; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
  .ui-card:active { background: var(--soft); }
  .ui-card img, .ui-card .ui-card-noimage { width: 4rem; height: 4rem; border-radius: .25rem; background: #fff; object-fit: contain; }
  .ui-card .ui-card-noimage { background: var(--soft); }
  .ui-card-name { font-size: .85rem; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .ui-card-meta { margin-top: .15rem; font-size: .7rem; color: var(--muted); }
  .ui-card-price { margin-top: .35rem; display: flex; align-items: baseline; gap: .5rem; font-size: 1.05rem; font-weight: 800; font-variant-numeric: tabular-nums; }
  .ui-card-price .change { font-size: .75rem; font-weight: 700; }
  .ui-card-trade { margin-top: .1rem; font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
  .ui-card-foot { margin-top: .35rem; display: flex; align-items: center; justify-content: space-between; gap: .5rem; font-size: .7rem; }
  .ui-stock::before { content: ''; display: inline-block; width: .5rem; height: .5rem; margin-right: .35rem; border-radius: 50%; background: #9ca3af; }
  .ui-stock[data-in="true"]::before { background: #16a34a; }
  .ui-card-compare { color: #df1830; text-decoration: underline; background: none; border: 0; padding: .25rem 0; font-size: .7rem; }
  .ui-cards-empty { padding: 2rem 1.25rem; text-align: center; font-size: .85rem; color: var(--muted); }

  /* Filters live in a bottom sheet. */
  .control-section { position: fixed; z-index: 60; left: 0; right: 0; bottom: 0; max-height: 82dvh; overflow-y: auto; overscroll-behavior: contain;
    background: var(--surface); border-radius: 1.25rem 1.25rem 0 0; box-shadow: 0 -8px 30px #0005; padding-bottom: calc(1.25rem + env(safe-area-inset-bottom)) !important;
    transform: translateY(105%); transition: transform .22s ease-out; visibility: hidden; }
  body.ui-filters-open .control-section { transform: none; visibility: visible; }
  .control-section > h2 { display: none; }
  .ui-sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem; position: sticky; top: -1.5rem; padding: 1rem 0 .5rem; margin-top: -1rem; background: var(--surface); z-index: 1; }
  .ui-sheet-head h2 { font-size: 1rem; font-weight: 700; margin: 0 !important; }
  .ui-backdrop { position: fixed; inset: 0; z-index: 55; background: #0007; }
  body.ui-filters-open .ui-backdrop { display: block; }
  body.ui-filters-open { overflow: hidden; }
  .control-section .field-label:not([for="sort"]) { display: none; }
  .control-section input, .control-section select { font-size: 16px !important; margin-top: .6rem; }

  /* Sticky bottom bar. */
  .ui-bar { display: grid; grid-template-columns: repeat(3, 1fr); position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; background: var(--surface);
    border-top: 1px solid var(--line); padding: .45rem .5rem calc(.45rem + env(safe-area-inset-bottom)); box-shadow: 0 -4px 16px #0001; }
  .ui-bar button { display: flex; flex-direction: column; align-items: center; gap: .2rem; padding: .35rem 0; font-size: .7rem; font-weight: 600; color: var(--ink); background: none; border: 0; border-radius: .5rem; }
  .ui-bar button i { font-size: 1.05rem; }
  .ui-bar .ui-bar-scan { color: #fff; background: #df1830; }
  .ui-bar button:active { background: var(--soft); }
  .ui-bar .ui-bar-scan:active { background: #b80e25; }
  .ui-bar-badge { position: relative; display: flex; }
  .ui-bar-badge .ui-filter-count { position: absolute; top: -.4rem; right: -.8rem; }
}
@media (prefers-reduced-motion: reduce) { .control-section { transition: none; } }

/* ---- Contrast: small grey labels on tinted backgrounds need a darker grey ---------- */
.table-frame th { color: color-mix(in srgb, var(--muted) 78%, var(--ink)) !important; }

/* ---- Price changes toolbar --------------------------------------------------------- */
.ui-change-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; margin: .25rem 0 .5rem; }
.ui-change-bar[hidden] { display: none; }
.ui-chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.ui-chip { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--line); border-radius: 1rem; padding: .3rem .75rem; font-size: .75rem; font-weight: 600; background: var(--surface); color: var(--ink); cursor: pointer; max-width: 16rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-chip:hover { border-color: #df1830; }
.ui-chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.ui-sort { font-size: .75rem; color: var(--muted); display: inline-flex; align-items: center; gap: .4rem; }
.ui-sort input { accent-color: #df1830; }
.ui-change-bar { justify-content: flex-start; }
.ui-change-bar .ui-chips { margin-right: auto; }
.ui-sort[hidden] { display: none; }
.ui-sort select { border: 1px solid var(--line); border-radius: .25rem; background: var(--surface); color: var(--ink); padding: .3rem .4rem; font-size: .75rem; }
.change small { font-weight: 600; }
.ui-card-was { font-size: .72rem; color: var(--muted); text-decoration: line-through; }

/* ---- Loading skeletons --------------------------------------------------------------- */
.ui-skeleton { display: block; height: .7rem; border-radius: .25rem; background: linear-gradient(90deg, var(--soft) 25%, var(--line) 50%, var(--soft) 75%); background-size: 200% 100%; }
@media (prefers-reduced-motion: no-preference) { .ui-skeleton { animation: ui-shimmer 1.2s linear infinite; } @keyframes ui-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } } }
.ui-skeleton-row td { padding-top: 1rem !important; padding-bottom: 1rem !important; }
.ui-card-skeleton .ui-skeleton + .ui-skeleton { margin-top: .5rem; }
.ui-skeleton-image { width: 4rem !important; height: 4rem !important; }
.ui-skeleton-short { width: 55%; }
.ui-skeleton-price { width: 35%; height: 1rem; }

/* ---- Image placeholders ---------------------------------------------------------- */
.ui-card-noimage { display: grid; place-items: center; color: var(--muted); font-size: 1.4rem; }

/* ---- Recent searches and scans ---------------------------------------------------- */
.ui-recent { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin-top: .6rem; }
.ui-recent[hidden] { display: none; }
.ui-recent-label { font-size: .7rem; color: var(--muted); margin-right: .15rem; }
.ui-recent .ui-chip { font-weight: 500; }
.ui-recent-clear { font-size: .7rem; color: var(--muted); text-decoration: underline; background: none; border: 0; cursor: pointer; }

/* ---- Watchlist ----------------------------------------------------------------------- */
.ui-star { background: none; border: 0; padding: .2rem .35rem; color: var(--muted); cursor: pointer; font-size: .9rem; }
.ui-star[aria-pressed="true"] { color: #e8a317; }
.ui-star:hover { color: #e8a317; }
td > .ui-star { margin-right: .25rem; }
.ui-card-actions { display: inline-flex; align-items: center; gap: .35rem; }
.ui-watch-drop { margin-top: .3rem; font-size: .72rem; font-weight: 700; color: #b7791f; }
.ui-watch-pill { display: inline-block; margin-left: .35rem; padding: 0 .4rem; border-radius: 1rem; background: #fdf3d7; color: #8a5a00; font-size: .65rem; font-weight: 700; }
.ui-tab-count { display: inline-block; min-width: 1.1rem; padding: 0 .3rem; border-radius: 1rem; background: var(--soft); color: var(--muted); font-size: .65rem; line-height: 1.1rem; text-align: center; }
.ui-tab-drop { color: #15803d; font-size: .7rem; font-weight: 700; }
.ui-tab-restock { color: #2563eb; font-size: .7rem; font-weight: 700; }
.ui-restock { margin-top: .3rem; font-size: .72rem; font-weight: 700; color: #2563eb; }

/* ---- My store ---------------------------------------------------------------------------- */
.ui-home { margin-top: .3rem; font-size: .72rem; font-weight: 700; color: #15803d; }
.ui-home i { color: #e8a317; }
.ui-home-none { color: var(--muted); font-weight: 400; }
.ui-home-box { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .6rem; margin-top: .4rem; font-size: .72rem; color: var(--muted); }
.ui-home-box[hidden] { display: none; }
.ui-home-box i { color: #e8a317; }
.ui-home-box strong { color: var(--ink); }
.ui-home-box button { background: none; border: 0; padding: 0; color: #df1830; font-weight: 600; text-decoration: underline; cursor: pointer; }

/* ---- Nearby stock ---------------------------------------------------------------------- */
.ui-near { margin-top: .3rem; font-size: .72rem; font-weight: 600; color: #15803d; }
.ui-near-none { color: var(--muted); font-weight: 400; }

/* ---- Compare tray ------------------------------------------------------------------------ */
.ui-compare-tray { position: fixed; z-index: 45; right: 1.25rem; bottom: 2.75rem; border: 0; border-radius: 2rem; padding: .7rem 1.1rem; background: var(--ink); color: var(--surface); font-size: .8rem; font-weight: 700; box-shadow: 0 6px 20px #0004; cursor: pointer; }
.ui-compare-tray[hidden] { display: none; }

/* ---- Desktop table: frozen product column; % columns optional ---------------------------- */
@media (width >= 48rem) {
  .table-frame table { min-width: 1120px !important; }
  body.ui-show-percent .table-frame table { min-width: 1320px !important; }
  .table-frame th:first-child, .table-frame td:first-child { position: sticky; left: 0; z-index: 2; background: var(--surface); box-shadow: 1px 0 0 var(--line); }
  .table-frame th:first-child { z-index: 12; background: var(--soft); }
  .table-frame tbody tr:hover td:first-child { background: color-mix(in srgb, #df1830 5%, var(--surface)); }
  body:not(.ui-show-percent) .table-frame th:nth-child(7), body:not(.ui-show-percent) .table-frame td:nth-child(7),
  body:not(.ui-show-percent) .table-frame th:nth-child(10), body:not(.ui-show-percent) .table-frame td:nth-child(10) { display: none; }
}
.ui-columns-toggle { display: inline-flex; align-items: center; gap: .35rem; margin-right: 1rem; font-size: .7rem; color: var(--muted); cursor: pointer; }

@media (width < 48rem) {
  .ui-compare-tray { bottom: calc(4.75rem + env(safe-area-inset-bottom)); right: .75rem; }
  .ui-change-bar { margin-top: .5rem; }
}

/* ---- Dark mode: keep red and amber readable on dark surfaces ------------------------- */
@media (prefers-color-scheme: dark) {
  .ui-card-compare, .ui-recent-clear:hover { color: #ff6b7d; }
  /* Brand red text is too dark on the dark background; buttons keep the brand red. */
  .text-brand, #back-results, a.text-brand { color: #ff6b7d !important; }
  .ui-tab[aria-selected="true"]::after { background: #ff4d63; }
  .scan-status[data-tone="warn"] { color: #fdba74; }
  .scan-status[data-tone="ok"], .ui-near, .ui-tab-drop, .ui-home { color: #4ade80; }
  .ui-home-none { color: var(--muted); }
  .ui-home-box button { color: #ff6b7d; }
  .ui-near-none { color: var(--muted); }
  .ui-watch-drop { color: #fbbf24; }
  .ui-restock, .ui-tab-restock { color: #93c5fd; }
  .ui-watch-pill { background: #4a3a10; color: #fde68a; }
  .ui-filter-count { background: #ff4d63; }
  .ui-card img, .ui-card-noimage { background: #fff1; }
  .ui-backdrop { background: #000a; }
}

/* ---- Sync & alerts dialog --------------------------------------------------------------- */
.sync-open { margin-left: .25rem; background: none; border: 0; padding: 0; color: #df1830; font-weight: 600; text-decoration: underline; cursor: pointer; font-size: inherit; }
.sync-dialog { width: min(94vw, 460px); margin: auto; padding: 1.25rem; border: 1px solid var(--line); border-radius: .5rem; background: var(--surface); color: var(--ink); }
.sync-dialog::backdrop { background: #000a; }
.sync-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.sync-head h2 { font-size: 1.15rem; font-weight: 700; }
.sync-head button, .sync-actions button, .sync-row button { border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: .55rem .9rem; font-size: .8rem; font-weight: 600; border-radius: .25rem; cursor: pointer; }
.sync-dialog section { border-top: 1px solid var(--line); padding: .9rem 0; }
.sync-dialog h3 { font-size: .9rem; font-weight: 700; margin-bottom: .35rem; }
.sync-dialog p, .sync-dialog label { font-size: .82rem; line-height: 1.45; color: var(--muted); }
.sync-code { margin: .5rem 0; font: 700 1.5rem/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .08em; color: var(--ink) !important; }
.sync-note { font-size: .75rem !important; }
.sync-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .6rem; }
.sync-actions .primary { background: #df1830; border-color: #df1830; color: #fff; }
.sync-dialog form { margin-top: .9rem; }
.sync-row { display: flex; gap: .5rem; margin-top: .35rem; }
.sync-row input { flex: 1; min-width: 0; border: 1px solid var(--line); background: var(--surface); color: var(--ink); padding: .55rem .7rem; font: 600 16px ui-monospace, monospace; text-transform: uppercase; border-radius: .25rem; }
.sync-toggle { display: flex; align-items: center; gap: .5rem; margin-top: .5rem; color: var(--ink) !important; font-weight: 600; }
.sync-toggle input { width: 1.1rem; height: 1.1rem; accent-color: #df1830; }
.sync-message { margin-top: .5rem; padding: .6rem .75rem; border-radius: .25rem; background: var(--soft); color: var(--ink) !important; }
.sync-error { color: #b91c1c !important; }
@media (prefers-color-scheme: dark) { .sync-open { color: #ff6b7d; } .sync-error { color: #fca5a5 !important; } }

/* ---- Search suggestions ------------------------------------------------------------------ */
.ui-suggest-host { position: relative; }
.ui-suggest { position: absolute; z-index: 40; left: 0; right: 0; top: 2.9rem; max-height: 22rem; overflow-y: auto; padding: .3rem; background: var(--surface); border: 1px solid var(--line); border-radius: .375rem; box-shadow: 0 10px 28px #0003; }
.ui-suggest[hidden] { display: none; }
.ui-suggest-item { display: flex; align-items: center; gap: .6rem; padding: .55rem .6rem; border-radius: .25rem; font-size: .85rem; color: var(--ink); cursor: pointer; }
.ui-suggest-item i { width: 1rem; text-align: center; color: var(--muted); font-size: .8rem; }
.ui-suggest-item span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ui-suggest-item small { font-size: .65rem; color: var(--muted); }
.ui-suggest-item mark { background: none; color: inherit; font-weight: 700; }
.ui-suggest-item:hover, .ui-suggest-item[aria-selected="true"] { background: var(--soft); }

/* ---- Desktop results header: use the full width ---------------------------------------- */
@media (width >= 48rem) {
  .results-header-copy { flex: 1 1 auto; display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 1.5rem; align-items: center; }
  .results-header-copy > * { grid-column: 1 / -1; }
  .results-header-copy > #status { grid-column: 1; margin: 0 !important; }
  .results-header-copy > .ui-meta { grid-column: 2; margin: 0; padding: 0; border: 0; gap: 1rem; }
  .ui-tabs { margin-bottom: .75rem; }
  .ui-change-bar { margin-bottom: .75rem; }
}
@media (48rem <= width < 72rem) {
  .results-header-copy > .ui-meta { grid-column: 1 / -1; margin-top: .6rem; }
}

.ui-target { margin-top: .3rem; font-size: .72rem; font-weight: 600; color: var(--muted); }
.ui-target.hit { color: #2f855a; font-weight: 700; }
@media (prefers-color-scheme: dark) { .ui-target.hit { color: #68d391; } }

.sync-delete p strong { color: var(--ink); }
.sync-actions button.danger { background: #c53030; border-color: #c53030; color: #fff; }
