:root {
  --bg0:    #0a0c10;
  --bg1:    #0f1218;
  --bg2:    #141820;
  --bg3:    #1a1f2a;
  --border: #232a38;
  --border2:#2e3748;
  --tx0:    #e8ecf4;
  --tx1:    #8b95aa;
  --tx2:    #4d5668;
  --c-new:   #2a78d6;
  --c-used:  #22c55e;
  --c-parts: #f5a623;
  --c-refurb: #8b5cf6;
  --c-scalp: #eab308;
  --c-down:  #ef4444;
  --c-up:    #22c55e;
  --c-flat:  #4d5668;
  --mono: 'IBM Plex Mono', monospace;
  --sans: 'Inter', sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html,body { background: var(--bg0); color: var(--tx0); font-family: var(--sans); font-size: 13px; height: 100%; overflow: hidden; }
body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
#filterbar { flex-shrink: 0; }

/* ---- Filter bar ---- */
#filterbar {
  height: 38px; background: var(--bg1); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; padding: 0 12px;
  flex-shrink: 0;
}
.fb-label { font-family: var(--mono); font-size: 10px; color: var(--tx2); text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
input.fb-search {
  height: 26px; background: var(--bg2); border: 1px solid var(--border); border-radius: 4px;
  padding: 0 10px; color: var(--tx0); font-family: var(--mono); font-size: 12px;
  width: 220px;
}
input.fb-search:focus { outline: none; border-color: var(--c-used); }
input.fb-search::placeholder { color: var(--tx2); }
select.fb-select {
  height: 26px; background: var(--bg2); border: 1px solid var(--border); border-radius: 4px;
  padding: 0 8px; color: var(--tx0); font-family: var(--mono); font-size: 11px; cursor: pointer;
}
.fb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.fb-spacer { flex:1; }

/* ---- Search syntax hint ---- */
.fb-hint {
  width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--tx2); font-family: var(--mono); font-size: 10px;
  cursor: help; user-select: none;
}
.fb-hint:hover { color: var(--tx0); border-color: var(--border2); }

/* ---- Favorites star ---- */
.fav-star {
  display: inline-block; width: 16px; margin-right: 6px;
  color: var(--tx2); cursor: pointer; font-size: 13px;
  transition: color 0.1s, transform 0.1s;
}
.fav-star:hover { transform: scale(1.25); color: #eab308; }
.fav-star.on { color: #eab308; }

/* ---- Saved searches ---- */
.fb-saved-del {
  height: 26px; width: 26px; border-radius: 4px;
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--tx2); font-family: var(--mono); font-size: 12px; cursor: pointer;
}
.fb-saved-del:hover { color: var(--c-down); border-color: var(--c-down); }
.fb-saved-save {
  height: 26px; padding: 0 8px; border-radius: 4px;
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--tx1); font-family: var(--mono); font-size: 11px; cursor: pointer;
  white-space: nowrap;
}
.fb-saved-save:hover { color: var(--tx0); border-color: var(--border2); }

/* ---- Category multi-select dropdown ---- */
.fb-cat-dropdown { position: relative; }
.fb-cat-toggle {
  height: 26px; padding: 0 10px; border-radius: 4px;
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--tx0); font-family: var(--mono); font-size: 11px;
  cursor: pointer; white-space: nowrap; display: flex; align-items: center; gap: 6px;
}
.fb-cat-toggle:hover { border-color: var(--border2); }
.fb-cat-toggle.has-filter { border-color: var(--c-used); color: var(--c-used); }
#deal-toggle.has-filter { border-color: #f97316; color: #f97316; }
#scalp-toggle.has-filter-scalp { border-color: #eab308; color: #eab308; }
.fb-cat-toggle .caret { font-size: 9px; opacity: 0.7; }
.fb-cat-panel {
  display: none; position: absolute; top: calc(100% + 4px); left: 0; z-index: 20;
  background: var(--bg2); border: 1px solid var(--border2); border-radius: 5px;
  padding: 6px; min-width: 170px; max-height: 260px; overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.fb-cat-panel.open { display: block; }
.fb-cat-item {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 6px; border-radius: 3px; cursor: pointer;
  font-family: var(--mono); font-size: 11px; color: var(--tx1);
}
.fb-cat-item:hover { background: var(--bg3); color: var(--tx0); }
.fb-cat-item input { accent-color: var(--c-used); cursor: pointer; }
.fb-cat-panel-footer {
  border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px;
  text-align: right;
}
.fb-cat-clear {
  font-family: var(--mono); font-size: 10px; color: var(--tx2);
  background: none; border: none; cursor: pointer; padding: 4px 6px;
}
.fb-cat-clear:hover { color: var(--tx0); }
.fb-count { font-family: var(--mono); font-size: 11px; color: var(--tx2); }

/* ---- Main layout ---- */
#table-wrap { flex: 1; overflow-y: auto; overflow-x: auto; -webkit-overflow-scrolling: touch; min-height: 0; }

/* ---- Table ---- */
table#t {
  width: 100%; border-collapse: collapse; table-layout: fixed;
  font-family: var(--mono); font-size: 12px;
}
table#t thead tr {
  background: var(--bg1); position: sticky; top: 0; z-index: 5;
  border-bottom: 1px solid var(--border2);
}
table#t th {
  padding: 7px 12px; text-align: left; position: relative;
  color: var(--tx2); font-size: 10px; font-weight: 500; text-transform: uppercase; letter-spacing: .05em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: pointer; user-select: none;
}
table#t th:hover { color: var(--tx1); }
table#t th.sorted { color: var(--tx0); }
table#t th .sort-arrow { margin-left: 4px; opacity: 0.5; }
table#t th.sorted .sort-arrow { opacity: 1; }
table#t td { padding: 6px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
table#t .right { text-align: right; }
table#t td.right { font-family: var(--mono); }

/* Column resize handles — a thin draggable strip on each resizable <th>'s
   right edge, matching the pointer-drag pattern already used for the
   panel splits (chipflip_panel_sizes). table-layout:fixed makes each <th>
   width authoritative for its whole column; #table-wrap's existing
   overflow-x:auto absorbs growth instead of needing to shrink a neighbor. */
.col-resize-handle {
  position: absolute; top: 0; right: 0; bottom: 0; width: 6px;
  cursor: col-resize; z-index: 1;
  border-right: 1px solid var(--tx2);   /* always-visible line so the handle is discoverable, not just on hover */
}
.col-resize-handle:hover, .col-resize-handle.resizing { border-right-color: var(--tx1); background: var(--border2); }
table#t tr.data-row { cursor: pointer; }
table#t tr.data-row:hover td { background: var(--bg2); }
table#t tr.data-row.selected td { background: var(--bg3); border-bottom-color: var(--border2); }
table#t tr.data-row.selected td:first-child { border-left: 2px solid var(--c-used); }

.cell-name { font-family: var(--sans); font-size: 13px; color: var(--tx0); }
.cell-cat {
  display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 3px;
  background: var(--bg3); color: var(--tx2); margin-top: 2px; font-family: var(--mono);
}
.cell-new  { color: var(--c-new); }
.cell-used { color: var(--c-used); }
.cell-parts { color: var(--c-parts); }
.cell-refurb { color: var(--c-refurb); }
.cell-demand { color: var(--tx1); }
.cell-margin-high { color: var(--c-used); font-weight: 500; }
.cell-margin-mid  { color: var(--c-parts); }
.cell-margin-low  { color: var(--tx1); }
.cell-na  { color: var(--tx2); }

.trend-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; padding: 2px 6px; border-radius: 3px;
}
.trend-up   { background: rgba(34,197,94,.12);  color: var(--c-used); }
.trend-down { background: rgba(239,68,68,.12);  color: var(--c-down); }
.trend-flat { background: var(--bg3); color: var(--tx2); }
.trend-none { color: var(--tx2); font-size: 11px; }

.hidden { display: none; }

/* #chart-body: dead — no element with this ID in the current 3-pane layout.
   #chart-canvas-wrap: removed — this ID rule's min-height:0 was beating
   .cf-chart-wrap's min-height:120px safety net (layout.css), letting the
   chart collapse to a sliver whenever the scrolling .cf-product-panel's
   other sections (buy rating, specs, etc.) filled the available height. */
#priceChart { width: 100% !important; height: 100% !important; }
/* #chart-placeholder styling now lives in layout.css's .cf-chart-placeholder
   (same element carries both). This ID rule used to duplicate it with
   display:flex — an ID selector, so it kept beating the .hidden utility
   class's display:none no matter what, leaving the "Loading price
   history…" text visibly overlapping the chart even once it had loaded. */

/* ---- Affiliate sidebar ---- */
#aff-links { display: flex; flex-direction: column; gap: 6px; }
.aff-link {
  display: flex; flex-direction: row; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 4px; text-decoration: none;
  border: 1px solid var(--border); background: var(--bg2);
  font-family: var(--mono); transition: border-color 0.1s, background 0.1s;
}
.aff-thumb {
  width: 36px; height: 36px; border-radius: 4px; flex-shrink: 0;
  background: var(--bg3); object-fit: contain;
}
.aff-info { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.aff-info .aff-title {
  font-size: 11px; color: var(--tx0); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.aff-info .aff-price { font-size: 11px; font-weight: 600; white-space: nowrap; }
.aff-info .aff-cond { font-size: 10px; font-weight: 400; color: var(--tx2); }
.aff-link.aff-new   .aff-price { color: var(--c-new); }
.aff-link.aff-used  .aff-price { color: var(--c-used); }
.aff-link.aff-parts .aff-price { color: var(--c-parts); }
.aff-link.aff-refurb .aff-price { color: var(--c-refurb); }
.aff-link:hover { background: var(--bg3); border-color: var(--border2); }
.aff-link.aff-disabled { opacity: 0.45; cursor: default; pointer-events: none; }

.aff-link.aff-deal { border-color: #f97316; box-shadow: 0 0 0 1px #f97316 inset; }
.aff-deal-badge { font-size: 11px; }

/* ---- Scrollbar ---- */
#table-wrap::-webkit-scrollbar { width: 6px; }
#table-wrap::-webkit-scrollbar-track { background: var(--bg1); }
#table-wrap::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }

/* ---- Empty / loading ---- */
.state-msg {
  padding: 40px; text-align: center;
  font-family: var(--mono); font-size: 12px; color: var(--tx2);
}

/* ---- GTM noscript fallback (only rendered with JS disabled) ---- */
.gtm-noscript-frame { display: none; visibility: hidden; }

/* ================================================================
   Tablet (<=860px) — everything stays visible, just reflows onto more
   rows so nothing overflows. No hamburger yet; there's enough width
   here to wrap sensibly without hiding controls.
   ================================================================ */
.tb-hamburger { display: none; }

@media (max-width: 860px) {
  #filterbar { flex-wrap: wrap; height: auto; padding: 8px 12px; row-gap: 8px; }
  input.fb-search { flex: 1 1 100%; order: -1; width: auto; }
  .fb-sep { display: none; }
  .fb-spacer { display: none; }
  .fb-count { flex-basis: 100%; text-align: right; }

  /* Table keeps every column — shrinks padding/font first, still
     scrolls horizontally past min-width rather than squeezing illegible. */
  table#t { min-width: 520px; font-size: 11px; }
  table#t th, table#t td { padding: 5px 8px; }
}

/* ================================================================
   Phone (<=640px) — only genuinely narrow screens get the hamburger.
   Collapsed state shows just the logo/name + hamburger; tapping it
   reveals BOTH the topbar's nav/social/stats AND the entire filterbar
   (search included) in one dropdown — nothing else in the bar.
   ================================================================ */
@media (max-width: 640px) {
  #topbar { height: 56px; overflow: hidden; }
  .tb-nav, .tb-social, .tb-stat, .tb-spacer { display: none; }

  .tb-hamburger {
    display: flex; align-items: center; justify-content: center;
    width: 44px; height: 56px; margin-left: auto;
    background: none; border: none; cursor: pointer;
    color: var(--c-used); font-size: 20px;
  }
  .tb-hamburger[aria-expanded="true"] { color: var(--c-new); }

  #filterbar { display: none; }

  body.mobile-menu-open #topbar { flex-wrap: wrap; height: auto; overflow: visible; }
  body.mobile-menu-open .tb-nav,
  body.mobile-menu-open .tb-social,
  body.mobile-menu-open .tb-stat { display: flex; flex-basis: 100%; }
  body.mobile-menu-open .tb-nav { flex-direction: column; height: auto; }
  body.mobile-menu-open .tb-nav a { border-right: none; border-top: 1px solid var(--border); padding: 10px 20px; }
  body.mobile-menu-open .tb-social { padding: 10px 20px; border-left: none; border-top: 1px solid var(--border); }
  body.mobile-menu-open .tb-stat { height: auto; border-left: none; border-top: 1px solid var(--border); padding: 8px 20px; }

  body.mobile-menu-open #filterbar {
    display: flex; flex-wrap: wrap; height: auto; padding: 12px; row-gap: 10px;
  }
  body.mobile-menu-open input.fb-search { flex-basis: 100%; width: auto; }
  body.mobile-menu-open .fb-label { flex-basis: 100%; }
  body.mobile-menu-open .fb-sep { display: none; }
  body.mobile-menu-open .fb-spacer { display: none; }
  body.mobile-menu-open .fb-count { flex-basis: 100%; text-align: right; }
}
