/* ── Ledger Card System ── */

/* Grid container */
.item-grid-brutal {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  border: var(--border);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: var(--white);
}

/* ── Ledger Card (grid mode) ── */
.item-card-brutal {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  background: var(--white);
  padding: 10px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: background 0.15s;
  position: relative;
}
.item-card-brutal:hover { background: #fef9f2; }

/* ── Ledger Cover ── */
.ledger-cover {
  position: relative;
  border: 2px solid var(--ink);
  background: #f7f4ee;
  min-height: 126px;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.ledger-cover .product-img {
  width: 100%;
  height: 126px;
  object-fit: contain;
}

/* ── Deal Badge (overlay) ── */
.deal-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  display: inline-flex;
  align-items: center;
  border: 2px solid var(--ink);
  background: var(--pink);
  color: #fff;
  padding: 4px 7px;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  box-shadow: 2px 2px 0 var(--ink);
  white-space: nowrap;
  z-index: 2;
}
.deal-badge.free { background: linear-gradient(135deg, var(--pink), var(--purple)); }
.deal-badge.heat-95 { background: #dc2626; }
.deal-badge.heat-90 { background: #ea580c; }
.deal-badge.heat-80 { background: #d97706; }
.deal-badge.heat-70 { background: #ca8a04; }
.deal-badge.heat-50 { background: #65a30d; }
.deal-badge.heat-30 { background: #0891b2; }

/* ── Dots Menu & Price History (inside cover) ── */
.item-dots-menu { position: absolute; top: 4px; right: 4px; z-index: 10; }
.item-dots-btn {
  width: 24px; height: 24px; background: rgba(255,255,255,0.9); border: 1px solid #ddd;
  border-radius: 4px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: #666; transition: all 0.12s; padding: 0;
}
.item-dots-btn:hover { background: white; color: var(--ink); }
.item-dots-dropdown {
  display: none; position: absolute; top: calc(100% + 2px); right: 0; min-width: 110px;
  background: var(--white); border: var(--border); box-shadow: var(--shadow); z-index: 20;
}
.item-dots-menu.open .item-dots-dropdown { display: block; }
.item-dots-dropdown button {
  display: block; width: 100%; text-align: left; padding: 0.45rem 0.65rem;
  border: none; background: none; font-family: var(--mono); font-size: 0.6rem;
  font-weight: 700; cursor: pointer; color: var(--ink);
}
.item-dots-dropdown button:hover { background: rgba(168,85,247,0.08); }
.item-dots-dropdown a {
  display: block; width: 100%; text-align: left; padding: 0.45rem 0.65rem;
  border: none; background: none; font-family: var(--mono); font-size: 0.6rem;
  font-weight: 700; color: var(--ink); text-decoration: none;
}
.item-dots-dropdown a:hover { background: rgba(168,85,247,0.08); }

.ph-icon-btn {
  position: absolute; top: 4px; right: 32px; z-index: 10; width: 24px; height: 24px;
  background: rgba(255,255,255,0.9); border: 1px solid #ddd; border-radius: 4px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  color: #666; padding: 0; transition: all 0.12s;
}
.ph-icon-btn:hover { background: white; color: var(--ink); }

/* ── Title ── */
.item-title-wrapper { min-width: 0; cursor: pointer; }
.item-title-brutal {
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Price ── */
.price-brutal { display: flex; align-items: baseline; gap: 0.5rem; }
.price-sale { font-family: var(--mono); font-size: 1.5rem; font-weight: 700; letter-spacing: -0.03em; }
.price-sale.free { color: var(--pink); }
.price-original { font-family: var(--mono); font-size: 0.75rem; color: var(--muted); text-decoration: line-through; }

/* ── Fact Grid (2×2 spec table) ── */
.fact-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}
.fact {
  min-width: 0;
  border: 1.5px solid var(--ink);
  background: var(--white);
  padding: 5px 6px;
}
.fact b {
  display: block;
  font-family: var(--mono);
  color: #746a60;
  font-size: 8px;
  line-height: 1;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 3px;
}
.fact span {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 900;
  line-height: 1.1;
}
.fact.stock-low span { color: #ea580c; }
.fact.stock-sold span { color: var(--red); }
.fact.stock-ok span { color: var(--green); }
.fact.missing span { color: #8c837a; }
.fact.cond-new span { color: var(--green); }
.fact.cond-refurb span { color: #ea580c; }

/* ── Removed / Pinned banners ── */
.removed-banner {
  background: var(--red); color: white; padding: 0.3rem 0.6rem; border-radius: 0;
  font-family: var(--mono); font-size: 0.6rem; font-weight: 700; text-align: center;
  text-transform: uppercase; letter-spacing: 0.05em;
}
.pinned-badge {
  font-family: var(--mono); font-size: 0.55rem; font-weight: 700;
  color: var(--purple); text-transform: uppercase; letter-spacing: 0.05em;
}

/* ── ATC Button ── */
.atc-brutal {
  display: block; text-align: center; padding: 0.55rem;
  font-family: var(--mono); font-weight: 700; font-size: 0.7rem;
  text-transform: uppercase; letter-spacing: 0.08em;
  border: 2px solid var(--ink); background: linear-gradient(135deg, var(--pink), var(--purple));
  color: var(--white); box-shadow: 2px 2px 0 var(--ink);
  transition: all 0.12s; text-decoration: none; border-radius: 0;
}
.atc-brutal:hover { box-shadow: var(--shadow-hover); transform: translate(1px, 1px); }
.atc-short { display: none; }
.grid-mode .atc-full { display: none; }
.grid-mode .atc-short { display: inline; }

/* ── Cart Qty Controls ── */
.cart-widget { width: 100%; }
.cart-qty-controls { display: flex; align-items: stretch; overflow: hidden; background: linear-gradient(135deg, var(--pink), var(--purple)); }
.cart-qty-btn {
  width: 40px; min-width: 44px; min-height: 44px; border: none; background: transparent;
  font-family: var(--mono); font-size: 1.1rem; font-weight: 700; cursor: pointer;
  transition: background 0.1s; color: white; padding: 0.5rem 0;
}
.cart-qty-btn:hover { background: rgba(0,0,0,0.15); }
.cart-qty-value {
  flex: 1; display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 0.9rem; font-weight: 700; color: white;
}

/* ── Actions Row ── */
.card-actions-row { display: flex; align-items: center; gap: 0.5rem; margin-top: auto; }

/* ── Variant Pills ── */
.variant-pills { display: flex; flex-wrap: wrap; gap: 0.3rem; margin: 0.2rem 0; }
.variant-pill {
  font-family: var(--mono); font-size: 0.6rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.03em; padding: 0.25rem 0.5rem; border: 2px solid var(--line);
  background: var(--white); color: var(--ink); cursor: pointer; transition: all 0.12s;
  line-height: 1; white-space: nowrap;
}
.variant-pill:hover { border-color: var(--purple); background: rgba(168,85,247,0.05); }
.variant-pill.active { background: var(--ink); color: white; border-color: var(--ink); }
.variant-count-badge {
  display: inline-block; flex-shrink: 0; padding: 3px 7px;
  font-family: var(--mono); font-size: 0.55rem; font-weight: 700;
  color: var(--purple); background: rgba(168,85,247,0.1);
  border-radius: 999px; text-transform: uppercase; letter-spacing: 0.03em;
  white-space: nowrap; line-height: 1;
}
.vm-trigger {
  font-family: var(--mono); font-size: 0.65rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; padding: 0.4rem 0.75rem; border: 2px solid var(--ink);
  background: var(--white); color: var(--ink); cursor: pointer; transition: all 0.12s;
  white-space: nowrap; text-align: center;
}
.vm-trigger:hover { background: var(--ink); color: var(--white); }
.vm-trigger-mobile { display: none; }

/* ── Filter Bar ── */
.filter-bar {
  background: var(--white); border: 2px solid var(--ink); border-top: none;
  padding: 0.6rem 1rem; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap;
}
.filter-group { display: flex; align-items: center; }
.filter-label {
  font-family: var(--mono); font-size: 0.6rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--ink); background: #f0f0f0;
  padding: 0.35rem 0.6rem; border: 2px solid var(--ink); border-right: none; border-radius: 0;
}
.filter-btn {
  font-family: var(--mono); font-size: 0.6rem; font-weight: 700; padding: 0.35rem 0.55rem;
  border: 2px solid var(--ink); border-left: none; background: var(--white); color: var(--ink);
  cursor: pointer; transition: all 0.1s; text-transform: uppercase; letter-spacing: 0.02em;
}
.filter-btn:hover { background: #f5f5f5; }
.filter-btn.active { background: var(--ink); color: var(--white); }
.filter-search {
  font-family: var(--mono); font-size: 0.65rem; padding: 0.35rem 0.6rem;
  border: 2px solid var(--ink); background: var(--white); outline: none; width: 140px;
  transition: box-shadow 0.15s; margin-left: auto;
}
.filter-search:focus { box-shadow: 3px 3px 0 var(--purple); }
.filter-search::placeholder { color: #bbb; }
.filter-count { font-family: var(--mono); font-size: 0.6rem; color: #999; white-space: nowrap; }

/* Mobile filter bar */
.filter-mobile { display: none; }
@media (max-width: 768px) {
  .filter-desktop { display: none !important; }
  .filter-mobile { display: block !important; }
  .filter-bar.filter-mobile { padding: 0.75rem; border: 2px solid var(--ink); border-top: none; background: var(--white); }
}
.fm-row1 { display: flex; align-items: center; gap: 0.5rem; }
.fm-action {
  display: flex; align-items: center; gap: 0.4rem; height: 44px; padding: 0 1rem;
  border: 2px solid var(--ink); background: var(--white); font-family: var(--mono);
  font-size: 0.7rem; font-weight: 700; cursor: pointer; transition: all 0.12s; color: var(--ink);
}
.fm-action:hover { background: #f5f5f5; }
.fm-action-icon { font-size: 1rem; }
.fm-action-label { white-space: nowrap; }
.fm-view-toggle { display: flex; border: 2px solid var(--ink); overflow: hidden; margin-left: auto; }
.fm-view-btn {
  width: 44px; height: 44px; border: none; background: var(--white);
  font-size: 1.1rem; cursor: pointer; transition: all 0.1s; color: var(--ink);
}
.fm-view-btn + .fm-view-btn { border-left: 2px solid var(--ink); }
.fm-view-btn.active { background: var(--ink); color: var(--white); }
.fm-row2 { margin-top: 0.5rem; }
.fm-search {
  width: 100%; height: 44px; padding: 0 1rem; border: 2px solid var(--ink);
  background: var(--white); font-family: var(--mono); font-size: 16px; outline: none;
}
.fm-search:focus { box-shadow: 3px 3px 0 var(--purple); }
.fm-search::placeholder { color: #bbb; }

/* ── Bottom Sheet ── */
.sheet-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 1000; flex-direction: column; justify-content: flex-end;
}
.sheet-overlay.open { display: flex; }
.sheet-card {
  background: var(--white); width: 100%; max-height: 70vh; padding: 1.5rem;
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
  animation: sheetUp 0.25s ease;
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.sheet-title { font-family: var(--sans); font-size: 1.25rem; font-weight: 700; }
.sheet-close {
  width: 36px; height: 36px; border: none; background: #f0f0f0; border-radius: 999px;
  font-size: 1.25rem; cursor: pointer; display: flex; align-items: center; justify-content: center; color: #666;
}
.sheet-options { display: flex; flex-direction: column; gap: 0.5rem; }
.sheet-options-grid { display: flex; flex-wrap: wrap; flex-direction: row; gap: 0.5rem; }
.sheet-opt {
  height: 48px; padding: 0 1.25rem; border: 2px solid var(--line);
  background: var(--white); font-family: var(--mono); font-size: 0.8rem; font-weight: 700;
  cursor: pointer; transition: all 0.15s; color: var(--ink); text-align: left;
  display: flex; align-items: center;
}
.sheet-options-grid .sheet-opt { flex: 0 0 auto; text-align: center; justify-content: center; }
.sheet-opt:hover { border-color: var(--ink); }
.sheet-opt.active { background: var(--gradient); color: white; border: none; padding: 0 calc(1.25rem + 2px); height: 52px; }

/* ── Collapse Button ── */
.collapse-btn {
  display: flex; align-items: center; justify-content: center; gap: 0.5rem;
  width: 100%; padding: 0.75rem; font-family: var(--mono); font-weight: 700;
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em;
  border: 2px solid var(--ink); border-top: none; background: var(--white);
  color: var(--ink); cursor: pointer; transition: all 0.15s;
}
.collapse-btn:hover { background: var(--gradient); color: white; }
.collapse-arrow { font-size: 1rem; transition: transform 0.2s; }

/* ── List Mode: single-column horizontal rows ── */
.item-grid-brutal:not(.grid-mode) { grid-template-columns: 1fr; }
.item-grid-brutal:not(.grid-mode) .item-card-brutal {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
  padding: 0.5rem 2.5rem 0.5rem 0.75rem;
  gap: 0.3rem 0.75rem;
  border-right: none;
}
.item-grid-brutal:not(.grid-mode) .item-card-brutal:hover { background: #fef9f2; }

/* Cover: compact square */
.item-grid-brutal:not(.grid-mode) .ledger-cover {
  flex-shrink: 0; width: 70px; min-height: auto; border-width: 1.5px;
}
.item-grid-brutal:not(.grid-mode) .ledger-cover .product-img { height: 60px; }
.item-grid-brutal:not(.grid-mode) .deal-badge { font-size: 8px; padding: 2px 5px; box-shadow: 1px 1px 0 var(--ink); top: 3px; left: 3px; }
.item-grid-brutal:not(.grid-mode) .ph-icon-btn { display: none; }
/* Move dots menu from cover to card's top-right so it doesn't obscure the small image */
.item-grid-brutal:not(.grid-mode) .ledger-cover { position: static; }
.item-grid-brutal:not(.grid-mode) .item-dots-menu { position: absolute; top: 6px; right: 6px; left: auto; }
.item-grid-brutal:not(.grid-mode) .item-dots-dropdown { right: 0; left: auto; }

/* Title: fills remaining space — works for both .item-title-wrapper (single) and .title-row (grouped) */
.item-grid-brutal:not(.grid-mode) .item-title-wrapper { flex: 1; min-width: 0; }
.item-grid-brutal:not(.grid-mode) .title-row { flex: 1; min-width: 0; }
.item-grid-brutal:not(.grid-mode) .item-title-brutal {
  font-size: 0.78rem; -webkit-line-clamp: 1; white-space: nowrap;
  text-overflow: ellipsis; overflow: hidden; display: block;
}

/* Price: right-aligned */
.item-grid-brutal:not(.grid-mode) .price-brutal {
  flex-shrink: 0; flex-direction: column; align-items: flex-end; gap: 0;
  margin: 0; margin-left: auto;
}
.item-grid-brutal:not(.grid-mode) .price-sale { font-size: 1.05rem; }
.item-grid-brutal:not(.grid-mode) .price-original { font-size: 0.6rem; }

/* Fact grid: transforms from 2×2 table into inline tag strip */
.item-grid-brutal:not(.grid-mode) .fact-grid {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.25rem;
  width: 100%;
  order: 10;
  padding-left: calc(70px + 0.75rem); /* indent past cover image */
  overflow-x: auto;
  scrollbar-width: none;
}
.item-grid-brutal:not(.grid-mode) .fact-grid::-webkit-scrollbar { display: none; }
.item-grid-brutal:not(.grid-mode) .fact {
  border: 1px solid #e0dbd4;
  background: #faf8f4;
  padding: 1px 6px;
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  flex-shrink: 0;
}
.item-grid-brutal:not(.grid-mode) .fact b {
  display: inline;
  font-size: 7px;
  margin: 0;
  color: #9a918a;
}
.item-grid-brutal:not(.grid-mode) .fact span { font-size: 0.58rem; }
.item-grid-brutal:not(.grid-mode) .fact.missing { display: none; }

/* Actions row: full-width bottom row */
.item-grid-brutal:not(.grid-mode) .card-actions-row {
  width: 100%; order: 20; gap: 0.4rem; padding-top: 0.3rem;
  border-top: 1px solid #f0f0f0; margin: 0; justify-content: space-between;
}
.item-grid-brutal:not(.grid-mode) .community-bar { order: -1; }
.item-grid-brutal:not(.grid-mode) .cart-widget { flex: none !important; max-width: 140px; }
.item-grid-brutal:not(.grid-mode) .atc-full { display: none; }
.item-grid-brutal:not(.grid-mode) .atc-short { display: inline; }
.item-grid-brutal:not(.grid-mode) .atc-brutal { font-size: 0.6rem; padding: 0.3rem 0.6rem; }
.item-grid-brutal:not(.grid-mode) .vm-trigger {
  flex: none !important; width: auto; max-width: 160px;
  font-size: 0.6rem; padding: 0.3rem 0.6rem; box-shadow: none;
}
.item-grid-brutal:not(.grid-mode) .vm-trigger-mobile { display: none; }
.item-grid-brutal:not(.grid-mode) .variant-pills-desktop { display: none !important; }
.item-grid-brutal:not(.grid-mode) .variant-count-badge { font-size: 0.5rem; padding: 2px 5px; }
.item-grid-brutal:not(.grid-mode) .removed-banner { width: 100%; order: -1; }
.item-grid-brutal:not(.grid-mode) .pinned-badge { display: none; }

/* Title marquee on hover */
.item-grid-brutal:not(.grid-mode) .item-card-brutal:hover .item-title-brutal {
  text-overflow: clip; width: max-content; overflow: visible; animation: title-marquee 10s linear infinite;
}
@keyframes title-marquee { 0%, 8% { transform: translateX(0); } 92%, 100% { transform: translateX(calc(-100% + 300px)); } }
.cart-title-wrapper:hover .cart-title-text {
  text-overflow: clip; width: max-content; overflow: visible; animation: title-marquee 10s linear infinite;
}

/* ── Responsive: Cards ── */
@media (max-width: 768px) {
  .item-grid-brutal.grid-mode { grid-template-columns: 1fr 1fr; }
  .grid-mode .item-card-brutal { padding: 8px; gap: 6px; }
  .grid-mode .ledger-cover { min-height: 88px; }
  .grid-mode .ledger-cover .product-img { height: 88px; }
  .grid-mode .item-title-brutal { font-size: 0.72rem; -webkit-line-clamp: 2; word-break: break-word; }
  .grid-mode .price-sale { font-size: 1.05rem; }
  .grid-mode .price-original { font-size: 0.6rem; }
  .grid-mode .fact-grid { gap: 3px; }
  .grid-mode .fact { padding: 4px 5px; }
  .grid-mode .fact b { font-size: 7px; }
  .grid-mode .fact span { font-size: 9px; }
  .grid-mode .atc-full { display: none; }
  .grid-mode .atc-short { display: inline; }
  .grid-mode .atc-brutal { font-size: 0.6rem; padding: 0.4rem; }
  .grid-mode .card-actions-row { flex-wrap: wrap; gap: 0.3rem; }
  .grid-mode .variant-count-badge { font-size: 0.45rem; padding: 2px 5px; }
  .grid-mode .cart-qty-btn { width: 30px; min-height: 36px; font-size: 0.85rem; padding: 0.4rem 0; }
  .grid-mode .cart-qty-value { font-size: 0.75rem; }
  /* List mode tighter on tablet */
  .item-grid-brutal:not(.grid-mode) .ledger-cover { width: 60px; }
  .item-grid-brutal:not(.grid-mode) .ledger-cover .product-img { height: 50px; }
  .item-grid-brutal:not(.grid-mode) .fact-grid { padding-left: calc(60px + 0.75rem); }
  .item-grid-brutal:not(.grid-mode) .item-title-brutal { font-size: 0.72rem; }
  .item-grid-brutal:not(.grid-mode) .price-sale { font-size: 0.95rem; }
}
@media (max-width: 480px) {
  .item-grid-brutal { grid-template-columns: 1fr; }
  .item-grid-brutal.grid-mode { grid-template-columns: 1fr 1fr; }
  .item-grid-brutal:not(.grid-mode) .item-card-brutal {
    padding: 0.4rem 0.5rem; gap: 0.25rem 0.5rem;
  }
  .item-grid-brutal:not(.grid-mode) .ledger-cover { width: 48px; }
  .item-grid-brutal:not(.grid-mode) .ledger-cover .product-img { height: 42px; }
  .item-grid-brutal:not(.grid-mode) .item-title-brutal { font-size: 0.68rem; }
  .item-grid-brutal:not(.grid-mode) .price-sale { font-size: 0.85rem; }
  .item-grid-brutal:not(.grid-mode) .fact-grid { padding-left: calc(48px + 0.5rem); }
  .item-grid-brutal:not(.grid-mode) .fact { padding: 0 4px; }
  .item-grid-brutal:not(.grid-mode) .fact span { font-size: 0.52rem; }
  .grid-mode .item-card-brutal { padding: 7px; gap: 5px; }
  .grid-mode .ledger-cover { min-height: 80px; }
  .grid-mode .ledger-cover .product-img { height: 80px; }
  .grid-mode .deal-badge { font-size: 8px; padding: 3px 5px; }
  .grid-mode .item-title-brutal { font-size: 0.7rem; }
  .grid-mode .price-sale { font-size: 1rem; }
  .grid-mode .cart-qty-btn { width: 28px; min-height: 32px; }
  .collapse-btn { font-size: 0.7rem; padding: 0.6rem; }
  .variant-pill { padding: 0.2rem 0.4rem; font-size: 0.55rem; }
}
@media (max-width: 600px) {
  .variant-pills { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .variant-pills::-webkit-scrollbar { display: none; }
}

/* ── elist toggle ── */
.elist-container ~ .collapse-btn { display: none; }
.item-grid-brutal.elist-hidden { display: none !important; }
