/* ===== Design tokens ===== */
:root{
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --border: #e4e1da;
  --text: #241f1a;
  --text-dim: #6b6459;
  --brand: #1e3a5f;
  --brand-dark: #16283f;
  --brand-text: #1e3a5f;
  --accent: #d98a2b;
  --accent-dark: #b56f1c;
  --profit: #1f7a4d;
  --profit-bg: #eaf5ee;
  --profit-border: #cde8d6;
  --hover-bg: #e7e3db;
  --danger: #b23b3b;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(30,20,10,0.06);
  --shadow-lg: 0 12px 32px rgba(20,15,10,0.18);
}

@media (prefers-color-scheme: dark){
  :root:not([data-theme="light"]){
    --bg: #14171d;
    --surface: #1b1f27;
    --surface-2: #232834;
    --border: #2d3340;
    --text: #ece9e3;
    --text-dim: #9a9488;
    --brand-text: #7fa8d9;
    --profit-bg: #16281d;
    --profit-border: #234a30;
    --hover-bg: #2c3341;
  }
}
:root[data-theme="dark"]{
  --bg: #14171d;
  --surface: #1b1f27;
  --surface-2: #232834;
  --border: #2d3340;
  --text: #ece9e3;
  --text-dim: #9a9488;
  --brand-text: #7fa8d9;
  --profit-bg: #16281d;
  --profit-border: #234a30;
}

*{box-sizing:border-box;}
html,body{margin:0;padding:0;}
body{
  background:var(--bg);
  color:var(--text);
  font-family:-apple-system, BlinkMacSystemFont, "Segoe UI", "SF Arabic", Tahoma, Geneva, Arial, sans-serif;
  line-height:1.5;
  -webkit-font-smoothing:antialiased;
}
img{max-width:100%;display:block;}
button{font-family:inherit;}

.skip-link{
  position:absolute; right:-999px; top:0; background:var(--brand); color:#fff; padding:.6em 1em; z-index:200;
}
.skip-link:focus{right:.5em; top:.5em;}

/* ===== Header ===== */
.site-header{
  position:sticky; top:0; z-index:50;
  background:var(--brand);
  color:#fff;
  box-shadow:var(--shadow);
}
.header-inner{
  max-width:1200px; margin:0 auto;
  display:flex; align-items:center; justify-content:space-between;
  padding:.75rem 1rem;
  gap:.75rem;
}
.brand{display:flex; align-items:center; gap:.6rem;}
.brand-mark{font-size:1.8rem; line-height:1;}
.brand-text{display:flex; flex-direction:column; line-height:1.2;}
.brand-name{font-size:1.25rem; font-weight:800; letter-spacing:.02em;}
.brand-tag{font-size:.72rem; color:#cdd8e6; font-weight:500;}

.cart-btn{
  position:relative;
  display:flex; align-items:center; gap:.4rem;
  background:var(--accent);
  color:#241a0a;
  border:none; border-radius:999px;
  padding:.55rem 1rem;
  font-weight:700; font-size:.85rem;
  cursor:pointer;
  transition:background .15s ease, transform .1s ease;
}
.cart-btn:hover{background:var(--accent-dark); color:#fff;}
.cart-btn:active{transform:scale(.97);}
.cart-icon{font-size:1.05rem;}
.cart-count{
  background:var(--brand-dark); color:#fff;
  min-width:1.35rem; height:1.35rem; border-radius:999px;
  display:flex; align-items:center; justify-content:center;
  font-size:.72rem; font-weight:800; padding:0 .3rem;
}

.search-bar-wrap{
  max-width:1200px; margin:0 auto;
  padding:0 1rem .75rem;
}
.search-bar{
  width:100%;
  padding:.65rem 1rem;
  border-radius:10px;
  border:none;
  font-size:.95rem;
  background:rgba(255,255,255,.95);
}
.search-bar:focus{outline:2px solid var(--accent); outline-offset:1px;}

/* ===== Category nav ===== */
.category-nav{
  position:sticky; top:112px; z-index:40; /* JS overrides this with the real header height */
  display:flex; gap:.5rem; overflow-x:auto;
  padding:.7rem 1rem;
  background:var(--bg);
  border-bottom:1px solid var(--border);
  scrollbar-width:thin;
  -webkit-overflow-scrolling:touch;
}
.category-nav::-webkit-scrollbar{height:6px;}
.category-nav::-webkit-scrollbar-thumb{background:var(--border); border-radius:99px;}
.cat-chip{
  flex:0 0 auto;
  display:flex; align-items:center; gap:.4rem;
  padding:.5rem .95rem;
  border-radius:999px;
  border:1px solid var(--border);
  background:var(--surface);
  color:var(--text);
  font-size:.85rem; font-weight:600;
  cursor:pointer;
  white-space:nowrap;
  transition:all .15s ease;
}
.cat-chip .chip-count{color:var(--text-dim); font-weight:500;}
.cat-chip:hover{border-color:var(--brand);}
.cat-chip.active{
  background:var(--brand); border-color:var(--brand); color:#fff;
}
.cat-chip.active .chip-count{color:#cdd8e6;}

/* ===== Layout ===== */
main{max-width:1200px; margin:0 auto; padding:1rem;}

.empty-state{padding:3rem 1rem; text-align:center; color:var(--text-dim);}
.hidden{display:none !important;}

/* ===== Product grid ===== */
.product-grid{
  display:grid;
  grid-template-columns:repeat(2, 1fr);
  gap:.85rem;
}
@media (min-width:640px){
  .product-grid{grid-template-columns:repeat(3, 1fr);}
}
@media (min-width:900px){
  .product-grid{grid-template-columns:repeat(4, 1fr);}
}
@media (min-width:1150px){
  .product-grid{grid-template-columns:repeat(5, 1fr);}
}

.product-card{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius);
  overflow:hidden;
  display:flex; flex-direction:column;
  box-shadow:var(--shadow);
}
.card-media{
  aspect-ratio:1/1;
  background:var(--surface-2);
  overflow:hidden;
  position:relative;
  cursor:zoom-in;
}
.card-media img{width:100%; height:100%; object-fit:cover;}
.card-code{
  position:absolute; top:.4rem; inset-inline-start:.4rem;
  background:rgba(30,25,20,.68); color:#fff;
  font-size:.68rem; font-weight:700;
  padding:.15rem .5rem; border-radius:6px;
  letter-spacing:.02em;
}
.card-zoom-hint{
  position:absolute; bottom:.4rem; inset-inline-end:.4rem;
  background:rgba(30,25,20,.6); color:#fff;
  width:1.6rem; height:1.6rem; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  font-size:.85rem; pointer-events:none;
}

/* ===== Lightbox ===== */
.lightbox{
  position:fixed; inset:0; z-index:120;
  background:rgba(10,8,6,.88);
  display:flex; align-items:center; justify-content:center;
  padding:2rem;
  cursor:zoom-out;
}
.lightbox img{
  max-width:min(92vw, 640px); max-height:88vh;
  object-fit:contain;
  border-radius:10px;
  background:var(--surface);
  box-shadow:var(--shadow-lg);
}
.lightbox-close{
  position:absolute; top:1rem; inset-inline-end:1rem;
  width:2.4rem; height:2.4rem; border-radius:50%;
  background:rgba(255,255,255,.14); border:1px solid rgba(255,255,255,.3);
  color:#fff; font-size:1.1rem; cursor:pointer;
}
.card-body{padding:.6rem .7rem .75rem; display:flex; flex-direction:column; gap:.4rem; flex:1;}
.card-name{font-size:.85rem; font-weight:600; line-height:1.35; min-height:2.4em;}
.card-pack{font-size:.72rem; color:var(--text-dim);}
.card-price-row{display:flex; align-items:baseline; justify-content:space-between; margin-top:auto;}
.card-price{font-size:1.05rem; font-weight:800; color:var(--brand-text);}
.card-price small{font-size:.65rem; font-weight:600; color:var(--text-dim);}

.card-toggle{
  display:flex; align-items:center; justify-content:center; gap:.3rem;
  background:var(--surface-2);
  border:1px solid var(--border);
  border-radius:9px;
  padding:.45rem;
  font-size:.78rem; font-weight:700; color:var(--brand-text);
  cursor:pointer;
}
.card-toggle:hover{background:var(--hover-bg);}

/* Inline calculator */
.card-calc{
  border-top:1px dashed var(--border);
  padding-top:.55rem;
  display:flex; flex-direction:column; gap:.5rem;
}
.qty-row{display:flex; align-items:center; justify-content:space-between; gap:.4rem;}
.qty-row label{font-size:.75rem; color:var(--text-dim); font-weight:600;}
.qty-stepper{display:flex; align-items:center; border:1px solid var(--border); border-radius:8px; overflow:hidden;}
.qty-stepper button{
  width:1.9rem; height:1.9rem; border:none; background:var(--surface-2);
  font-size:1rem; font-weight:700; cursor:pointer; color:var(--brand-text);
}
.qty-stepper input{
  width:2.6rem; border:none; text-align:center; font-size:.85rem; font-weight:700;
  -moz-appearance:textfield;
}
.qty-stepper input::-webkit-outer-spin-button,
.qty-stepper input::-webkit-inner-spin-button{-webkit-appearance:none; margin:0;}

.calc-line{display:flex; justify-content:space-between; font-size:.78rem; color:var(--text-dim);}
.calc-line strong{color:var(--text); font-weight:700;}

.sell-price-row{display:flex; flex-direction:column; gap:.25rem;}
.sell-price-row label{font-size:.72rem; color:var(--text-dim); font-weight:600;}
.sell-price-row input{
  border:1px solid var(--border); border-radius:8px; padding:.4rem .55rem; font-size:.85rem;
}
.profit-line{
  display:flex; justify-content:space-between; align-items:center;
  background:var(--profit-bg); border:1px solid var(--profit-border); color:var(--profit);
  border-radius:8px; padding:.4rem .6rem; font-size:.78rem; font-weight:700;
}
.profit-line span:last-child{font-size:.95rem;}

.add-to-cart-btn{
  margin-top:.15rem;
  background:var(--brand); color:#fff; border:none; border-radius:9px;
  padding:.55rem; font-weight:700; font-size:.82rem; cursor:pointer;
}
.add-to-cart-btn:hover{background:var(--brand-dark);}
.add-to-cart-btn.added{background:var(--profit);}

/* ===== Cart drawer ===== */
.cart-overlay{
  position:fixed; inset:0; background:rgba(15,10,5,.45); z-index:90;
}
.cart-drawer{
  position:fixed; top:0; bottom:0; inset-inline-end:0;
  width:min(400px, 100%);
  background:var(--surface);
  z-index:95;
  display:flex; flex-direction:column;
  transform:translateX(-100%);
  transition:transform .25s ease;
  box-shadow:var(--shadow-lg);
}
.cart-drawer.open{transform:translateX(0);}

.cart-drawer-head{
  display:flex; align-items:center; justify-content:space-between;
  padding:1rem 1.1rem; border-bottom:1px solid var(--border);
}
.cart-drawer-head h2{font-size:1.05rem; margin:0;}
.icon-btn{background:none; border:none; font-size:1.1rem; cursor:pointer; color:var(--text-dim); padding:.2rem .4rem;}

.cart-items{flex:1; overflow-y:auto; padding:.5rem .9rem;}
.cart-empty{padding:2rem 1rem; text-align:center; color:var(--text-dim); font-size:.9rem;}

.cart-group-head{
  display:flex; align-items:center; gap:.4rem;
  font-size:.8rem; font-weight:800; color:var(--brand-text);
  padding:.6rem 0 .3rem;
}
.cart-group-head:first-child{padding-top:.1rem;}
.cart-group-head .chip-count{font-weight:600; color:var(--text-dim); font-size:.72rem;}

.cart-item{
  display:flex; gap:.6rem; padding:.7rem 0; border-bottom:1px solid var(--border);
}
.cart-item img{width:56px; height:56px; object-fit:cover; border-radius:8px; background:var(--surface-2); flex:0 0 auto;}
.cart-item-body{flex:1; display:flex; flex-direction:column; gap:.3rem;}
.cart-item-title{font-size:.82rem; font-weight:700;}
.cart-item-sub{font-size:.7rem; color:var(--text-dim);}
.cart-item-row{display:flex; align-items:center; justify-content:space-between; gap:.5rem;}
.cart-item-row .qty-stepper button{width:1.6rem; height:1.6rem;}
.cart-item-remove{background:none; border:none; color:var(--danger); font-size:.72rem; font-weight:700; cursor:pointer;}
.cart-item-total{font-size:.85rem; font-weight:800; color:var(--brand-text);}
.cart-item-sell{display:flex; align-items:center; gap:.4rem; font-size:.72rem; color:var(--text-dim);}
.cart-item-sell input{width:4.2rem; border:1px solid var(--border); border-radius:6px; padding:.2rem .4rem; font-size:.78rem;}

.cart-summary{border-top:1px solid var(--border); padding:.9rem 1.1rem 1.1rem; background:var(--surface-2);}
.summary-row{display:flex; justify-content:space-between; font-size:.85rem; padding:.22rem 0;}
.summary-dim{color:var(--text-dim);}
.summary-total{font-weight:800; font-size:.95rem; color:var(--brand-text);}
.profit-row{font-weight:800; color:var(--profit);}
.cart-actions{display:flex; gap:.5rem; margin-top:.7rem;}

.cart-breakdown{
  display:flex; flex-direction:column; gap:.5rem;
  margin-bottom:.6rem; padding-bottom:.6rem;
  border-bottom:1px dashed var(--border);
}
.breakdown-cat{
  display:flex; flex-direction:column; gap:.15rem;
  font-size:.76rem;
}
.breakdown-cat-head{
  display:flex; justify-content:space-between; font-weight:700; color:var(--text);
}
.breakdown-cat-line{
  display:flex; justify-content:space-between; color:var(--text-dim);
}
.breakdown-cat-line.profit{color:var(--profit); font-weight:700;}
.btn{flex:1; border:none; border-radius:9px; padding:.65rem; font-weight:700; font-size:.85rem; cursor:pointer;}
.btn-primary{background:#25D366; color:#06341a;}
.btn-primary:hover{background:#1ebc59;}
.btn-ghost{background:transparent; border:1px solid var(--border); color:var(--text-dim);}
.btn-ghost:hover{background:var(--hover-bg);}

/* ===== Footer ===== */
.site-footer{
  max-width:1200px; margin:1rem auto 2rem; padding:0 1rem;
  color:var(--text-dim); font-size:.75rem; text-align:center;
}

