/* ══════════════════════════════════════
   ПАЗАРНА СЦЕНА — цял екран
══════════════════════════════════════ */
#marketScene {
  position: relative;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: #071009;
}

/* Далечен фон — мести се обратно на мишката */
#sceneBg {
  position: absolute;
  inset: -18%;
  background: url('../../images/shop_bg.png') center / cover no-repeat;
  will-change: transform;
  z-index: 0;
}

/* Заглавие — горе, не участва в паралакса */
.scene-hdr {
  position: absolute;
  top: clamp(86px, 13vh, 132px);
  left: 0;
  right: 0;
  text-align: center;
  z-index: 20;
  pointer-events: none;
}

.scene-eyebrow {
  font-size: .68rem;
  letter-spacing: .22em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 10px;
}

.scene-title {
  font-size: clamp(2.6rem, 5.5vw, 5rem);
  font-weight: 900;
  line-height: .92;
  color: var(--white);
  text-shadow: 0 4px 48px rgba(0,0,0,.9), 0 2px 12px rgba(0,0,0,.7);
}

.scene-sub {
  margin-top: 14px;
  font-size: .8rem;
  color: rgba(255,255,255,.42);
  letter-spacing: .07em;
}

/* ── ТЪМЕН ГРАДИЕНТ (фона да не пречи на щайгите) ── */
#sceneGrad {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 75%;
  background: linear-gradient(transparent, rgba(7,16,9,.94) 70%);
  z-index: 5;
  pointer-events: none;
}

/* ── СКРОЛБОКС ПАНЕЛ ── */
#crateShelf {
  position: absolute;
  top: clamp(145px, 20vh, 190px);
  bottom: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  padding: 0;
  gap: 0;
}

/* Стрелки — скрити */
.crate-arr { display: none; }

/* Скролваща зона */
.scroll-row {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 18px 20px clamp(20px, 4vh, 52px);
  scrollbar-width: thin;
  scrollbar-color: rgba(0,255,136,.22) transparent;
}
.scroll-row::-webkit-scrollbar { width: 5px; }
.scroll-row::-webkit-scrollbar-track { background: transparent; }
.scroll-row::-webkit-scrollbar-thumb {
  background: rgba(0,255,136,.22);
  border-radius: 3px;
}

/* Продуктов грид */
#crateTrack {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(130px, 14vw, 190px), 1fr));
  gap: clamp(10px, 1.2vw, 16px);
  overflow: visible;
  cursor: default;
  padding: 0;
  scrollbar-width: none;
  scroll-snap-type: none;
  align-items: start;
}
#crateTrack::-webkit-scrollbar { display: none; }
#crateTrack.dragging { cursor: default; }

/* Щайга в грид */
#crateTrack .crate {
  flex: unset;
  width: 100%;
  scroll-snap-align: none;
}

/* ── ЩАЙГА ── */
.crate {
  cursor: pointer;
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: rgba(8,22,10,.7);
  border: 1px solid rgba(0,255,136,.1);
  backdrop-filter: blur(6px);
  transition:
    transform   .42s cubic-bezier(.34,1.56,.64,1),
    box-shadow  .42s ease,
    border-color .28s ease;
  flex-shrink: 0;
}

.crate:hover {
  transform: translateY(-10px) scale(1.04);
  box-shadow: 0 24px 56px rgba(0,255,136,.2);
  border-color: rgba(0,255,136,.4);
}

.crate:hover .crate-shine { opacity: 1; }

.crate-shine {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,.12) 0%, transparent 55%);
  opacity: 0;
  transition: opacity .35s;
  pointer-events: none;
  z-index: 2;
}

.crate-img {
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  display: block;
  transition: transform .55s cubic-bezier(.25,.46,.45,.94);
}

.crate:hover .crate-img { transform: scale(1.08); }

.crate-lbl {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 10px 8px;
  background: rgba(0,0,0,.55);
  position: relative;
  z-index: 2;
}

.cn {
  font-size: .78rem;
  font-weight: 700;
  color: var(--white);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cp {
  font-size: .72rem;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
  margin-left: 6px;
  flex-shrink: 0;
}

/* ══════════════════════════════════════
   ПРОДУКТОВ ПОПЪП
══════════════════════════════════════ */
#prodPopup {
  position: fixed;
  inset: 0;
  z-index: 950;
  display: none;
  align-items: center;
  justify-content: center;
}

#prodPopup.open { display: flex; }

#ppOverlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(10px);
  cursor: pointer;
}

#ppCard {
  position: relative;
  z-index: 1;
  background: #0f1e13;
  border: 1px solid rgba(0,255,136,.22);
  border-radius: 20px;
  overflow: hidden;
  width: min(400px, 92vw);
  display: flex;
  flex-direction: column;
  box-shadow: 0 40px 100px rgba(0,0,0,.8), 0 0 0 1px rgba(0,255,136,.06);
  animation: ppIn .36s cubic-bezier(.34,1.56,.64,1);
}

@keyframes ppIn {
  from { opacity: 0; transform: scale(.84) translateY(24px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}

#ppClose {
  position: absolute;
  top: 12px; right: 12px;
  background: rgba(0,0,0,.6);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 50%;
  width: 36px; height: 36px;
  color: var(--white);
  cursor: pointer;
  font-size: .85rem;
  display: flex; align-items: center; justify-content: center;
  z-index: 2;
  transition: background .2s;
}
#ppClose:hover { background: rgba(255,255,255,.15); }

#ppImg {
  width: 100%;
  aspect-ratio: 3 / 2;
  object-fit: cover;
  display: block;
}

#ppBody {
  padding: 20px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.pp-cat {
  font-size: .65rem;
  letter-spacing: .2em;
  text-transform: uppercase;
  color: var(--accent);
}

.pp-name {
  font-size: 1.45rem;
  font-weight: 900;
  color: var(--white);
  line-height: 1.1;
}

.pp-unit-price {
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: 2px;
}

.pp-qty-row {
  display: flex;
  align-items: center;
  gap: 20px;
  margin: 8px 0 2px;
}

.pp-qty-btn {
  background: rgba(0,255,136,.1);
  border: 1px solid rgba(0,255,136,.22);
  border-radius: 50%;
  width: 44px; height: 44px;
  color: var(--accent);
  font-size: 1.5rem;
  font-weight: 700;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .18s, transform .18s;
  font-family: inherit;
  flex-shrink: 0;
  line-height: 1;
}
.pp-qty-btn:hover { background: rgba(0,255,136,.22); transform: scale(1.12); }

.pp-qty-val {
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--white);
  min-width: 36px;
  text-align: center;
}

.pp-total {
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--accent);
  margin: 2px 0 8px;
}

.pp-add-btn {
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 10px;
  padding: 15px;
  font-size: .92rem;
  font-weight: 800;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: .04em;
  transition: background .25s, transform .2s, box-shadow .25s;
}
.pp-add-btn:hover {
  background: var(--a2);
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(0,255,136,.3);
}

/* ══════════════════════════════════════
   ПЛАВАЩА КОЛИЧКА
══════════════════════════════════════ */
.cart-fab {
  position: fixed; bottom: 32px; right: 32px; z-index: 800;
  width: 60px; height: 60px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--accent); color: #000;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 8px 28px rgba(0,255,136,.35);
  transition: transform .3s, box-shadow .3s;
}
.cart-fab:hover { transform: scale(1.1); box-shadow: 0 12px 36px rgba(0,255,136,.5); }
.cart-fab svg { width: 24px; height: 24px; }

.cart-badge {
  position: absolute; top: -5px; right: -5px;
  background: #FF3311; color: #fff; font-size: .68rem; font-weight: 900;
  min-width: 20px; height: 20px; border-radius: 10px; padding: 0 5px;
  display: flex; align-items: center; justify-content: center;
  transform: scale(0); transition: transform .3s cubic-bezier(.34,1.56,.64,1);
  pointer-events: none;
}
.cart-badge.vis { transform: scale(1); }

/* ── Overlay ── */
.cart-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 900;
  opacity: 0; pointer-events: none; transition: opacity .35s;
}
.cart-overlay.open { opacity: 1; pointer-events: all; }

/* ══════════════════════════════════════
   ПАНЕЛ КОЛИЧКА
══════════════════════════════════════ */
.cart-panel {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 901;
  width: min(460px, 100vw);
  background: var(--bg); border-left: 1px solid rgba(0,255,136,.12);
  display: flex; flex-direction: column;
  transform: translateX(110%); transition: transform .42s cubic-bezier(.76,0,.24,1);
}
.cart-panel.open { transform: translateX(0); }

.cp-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 22px 28px; border-bottom: 1px solid rgba(0,255,136,.1); flex-shrink: 0;
}
.cp-title { font-size: 1.05rem; font-weight: 700; color: var(--white); }
.cp-count-lbl { color: var(--muted); font-weight: 400; font-size: .9rem; }
.cp-x {
  background: none; border: 1px solid rgba(255,255,255,.1); border-radius: 8px;
  width: 36px; height: 36px; color: var(--muted); cursor: pointer; font-size: .95rem;
  display: flex; align-items: center; justify-content: center; transition: all .25s; flex-shrink: 0;
}
.cp-x:hover { border-color: var(--accent); color: var(--accent); }

.cp-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.cp-body::-webkit-scrollbar { width: 4px; }
.cp-body::-webkit-scrollbar-thumb { background: rgba(0,255,136,.2); border-radius: 2px; }

.cp-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--muted); padding: 60px 28px; }
.cp-empty-icon { font-size: 3rem; opacity: .4; }
.cp-empty p { font-size: .92rem; }

#cpItemsList { padding: 8px 0; }
.ci {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 28px; border-bottom: 1px solid rgba(0,255,136,.05);
  transition: background .2s;
}
.ci:hover { background: rgba(0,255,136,.02); }
.ci-img { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.ci-info { flex: 1; min-width: 0; }
.ci-name { font-size: .88rem; font-weight: 600; color: var(--white); margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ci-price { font-size: .78rem; color: var(--muted); }
.ci-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.ci-qty { display: flex; align-items: center; border: 1px solid rgba(0,255,136,.18); border-radius: 8px; overflow: hidden; }
.ci-qty button {
  background: none; border: none; color: var(--accent); width: 30px; height: 30px;
  cursor: pointer; font-size: 1.1rem; font-weight: 700; font-family: inherit;
  display: flex; align-items: center; justify-content: center; transition: background .2s;
}
.ci-qty button:hover { background: rgba(0,255,136,.1); }
.ci-qty span { font-size: .85rem; font-weight: 700; color: var(--white); min-width: 28px; text-align: center; }
.ci-del {
  background: none; border: none; color: rgba(255,80,80,.45); cursor: pointer;
  font-size: 1rem; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center;
  border-radius: 6px; transition: all .2s;
}
.ci-del:hover { background: rgba(255,50,50,.1); color: #FF4444; }

.cp-subtotal {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 28px; border-top: 1px solid rgba(0,255,136,.1); flex-shrink: 0;
}
.cp-subtotal span { font-size: .88rem; color: var(--muted); }
.cp-subtotal strong { font-size: 1.25rem; font-weight: 900; color: var(--accent); }

.cp-checkout { padding: 4px 28px 32px; flex-shrink: 0; }
.cp-section-lbl { font-size: .68rem; letter-spacing: .16em; text-transform: uppercase; color: var(--accent); margin-bottom: 20px; padding-top: 20px; border-top: 1px solid rgba(0,255,136,.08); }

input[type=date].fi { color-scheme: dark; }
input[type=date].fi::-webkit-calendar-picker-indicator { filter: invert(.5) sepia(1) saturate(3) hue-rotate(100deg); cursor: pointer; }
.fl.fo { top: -6px !important; font-size: 10px !important; color: var(--accent); letter-spacing: 4px; text-transform: uppercase; }
.fg.err .fi { border-color: rgba(255,60,60,.7); }
.fg.err .fl { color: rgba(255,80,80,.85); }
.cp-checkout .mw { display: block; width: 100%; margin-top: 4px; }
.cp-checkout .bsend { width: 100%; text-align: center; padding: 18px 0; border-radius: 8px; }

.cp-success { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 32px; text-align: center; }
.cps-icon { font-size: 4rem; margin-bottom: 16px; }
.cp-success h3 { font-size: 1.4rem; color: var(--accent); margin-bottom: 12px; }
.cp-success p { color: var(--muted); font-size: .92rem; line-height: 1.75; }
.cp-success strong { color: var(--white); }

/* ══════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════ */
@media (max-width: 600px) {
  #crateShelf { top: clamp(130px, 18vh, 170px); }
  #crateTrack {
    grid-template-columns: repeat(auto-fill, minmax(clamp(110px, 28vw, 150px), 1fr));
    gap: 9px;
  }
  .cn { font-size: .65rem; }
  .cp { font-size: .6rem; }
  .crate-lbl { padding: 5px 7px 6px; }
  .scene-title { font-size: clamp(1.8rem, 7vw, 2.6rem); }
  .sort-row { padding: 8px 12px; gap: 5px 8px; }
  .scroll-row { padding: 12px 12px clamp(16px, 3vh, 36px); }
}

@media (max-width: 480px) {
  .cart-fab { bottom: 20px; right: 16px; width: 52px; height: 52px; }
  .cart-fab svg { width: 20px; height: 20px; }
  .cp-head { padding: 18px 20px; }
  .ci { padding: 10px 20px; }
  .cp-subtotal, .cp-checkout { padding-left: 20px; padding-right: 20px; }
}

/* ══════════════════════════════════════
   ЩАЙГА — многоредов етикет + "N вида"
══════════════════════════════════════ */
.crate-lbl {
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}
.crate-lbl-main {
  display: flex;
  align-items: baseline;
  gap: 6px;
  width: 100%;
}
.crate-vars {
  font-size: .62rem;
  font-weight: 700;
  color: var(--accent);
  opacity: .8;
  white-space: nowrap;
  letter-spacing: .02em;
}
.crate-inactive {
  opacity: .55;
  cursor: default;
  pointer-events: none;
}
.crate-oos {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.55);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .72rem;
  font-weight: 800;
  color: rgba(255,255,255,.6);
  letter-spacing: .12em;
  text-transform: uppercase;
  z-index: 3;
}

/* ══════════════════════════════════════
   ПОПЪП — разновидности + наличност
══════════════════════════════════════ */
.pp-variants {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 6px 0 2px;
}

.pp-var-btn {
  padding: 6px 14px;
  border-radius: 20px;
  border: 1.5px solid rgba(0,255,136,.2);
  background: rgba(0,255,136,.05);
  color: rgba(240,255,244,.65);
  font-size: .78rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: border-color .15s, background .15s, color .15s;
  white-space: nowrap;
  line-height: 1.4;
}
.pp-var-btn:hover:not([disabled]) {
  border-color: rgba(0,255,136,.55);
  background: rgba(0,255,136,.1);
  color: #e8f5ec;
}
.pp-var-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #000;
}
.pp-var-btn.oos,
.pp-var-btn[disabled] {
  opacity: .38;
  cursor: not-allowed;
  text-decoration: line-through;
}
.pp-var-low {
  display: inline-block;
  font-size: .64rem;
  font-weight: 600;
  color: #ffd600;
  margin-left: 4px;
}
.pp-var-oos {
  display: inline-block;
  font-size: .64rem;
  font-weight: 600;
  color: #ff7070;
  margin-left: 4px;
}

/* Статус ред под разновидностите */
.pp-stock {
  font-size: .74rem;
  min-height: 16px;
  margin: 1px 0 3px;
}
.pp-stock.ok  { color: rgba(0,255,136,.7); }
.pp-stock.low { color: #ffd600; }
.pp-stock.oos { color: #ff5555; }

/* Бутон "Добави" — изчерпано */
.pp-add-btn:disabled {
  background: rgba(255,255,255,.12);
  color: rgba(255,255,255,.3);
}
