/* ============================================================
   BulkShopForAll - Telegram Mini App
   Stile professionale blu/bianco, adattivo al tema Telegram.
   ============================================================ */
:root {
  --brand: #0067b8;
  --brand-2: #0a78d6;
  --brand-grad: linear-gradient(135deg, #0067b8, #0a78d6);
  --danger: #df0000;

  /* Fallback chiari; sovrascritti dalle variabili del tema Telegram */
  --bg: var(--tg-theme-bg-color, #f2f7fd);
  --bg-2: var(--tg-theme-secondary-bg-color, #e8f1fa);
  --card: var(--tg-theme-section-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #0e1c2e);
  --hint: var(--tg-theme-hint-color, #5a6b7d);
  --border: color-mix(in srgb, var(--hint) 22%, transparent);

  --radius: 16px;
  --nav-h: 62px;
}
body.tg-dark {
  --brand-2: #2f9bff;
  --border: color-mix(in srgb, var(--hint) 35%, transparent);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 26px);
}
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img { display: block; max-width: 100%; }

/* ------------------------------ header ------------------------------ */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar__logo { width: 38px; height: 38px; border-radius: 50%; object-fit: contain; }
.topbar__title { font-weight: 800; font-size: 18px; letter-spacing: -0.02em; flex: 1; }
.topbar__title span { color: var(--brand-2); }
.topbar__lang {
  font-weight: 700; font-size: 13px;
  padding: 7px 10px; border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg); color: var(--text);
  appearance: none; -webkit-appearance: none;
}

/* --------------------------- search + filters ----------------------- */
.searchbar { padding: 10px 14px 0; }
.searchbar__box {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 10px 14px; color: var(--hint);
}
.searchbar__box input {
  flex: 1; border: none; outline: none; background: transparent;
  font-size: 15px; color: var(--text);
}
.filters { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.filters__select {
  flex: 1; min-width: 150px;
  padding: 9px 12px; border-radius: 12px; font-size: 13.5px; font-weight: 600;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
}
.filters__check {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13.5px; font-weight: 600; color: var(--hint);
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--card);
}
.filters__check input { accent-color: var(--brand); width: 16px; height: 16px; }

/* ------------------------------- grid ------------------------------- */
.view { padding: 12px 14px 20px; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(3, 1fr); } }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: transform .15s ease, box-shadow .15s ease;
}
.card:active { transform: scale(.98); }
.card__media { position: relative; background: #fff; aspect-ratio: 1/1; display: flex; align-items: center; justify-content: center; }
.card__media img { width: 100%; height: 100%; object-fit: contain; padding: 10px; }
.card__badge {
  position: absolute; top: 8px; left: 8px;
  background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 800; font-style: italic;
  padding: 4px 8px; border-radius: 8px;
}
.card__soldout {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.72); color: #333; font-weight: 800; font-size: 13px;
}
.card__body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card__title {
  font-size: 13.5px; font-weight: 700; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  min-height: 2.6em;
}
.card__price { margin-top: auto; display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap; }
.price { font-size: 16.5px; font-weight: 900; color: var(--danger); font-style: italic; }
.price--regular { color: var(--text); font-style: normal; }
.compare { font-size: 12px; color: var(--hint); text-decoration: line-through; }
.card__btn {
  margin-top: 8px;
  background: var(--brand-grad); color: #fff;
  font-weight: 800; font-size: 13.5px;
  padding: 11px 10px; border-radius: 12px; text-align: center;
  box-shadow: 0 6px 16px rgba(0,103,184,.28);
  transition: transform .15s ease, opacity .15s ease;
}
.card__btn:active { transform: scale(.96); }
.card__btn[disabled] { opacity: .45; box-shadow: none; }

/* ------------------------------ sections ---------------------------- */
.section-title { font-size: 19px; font-weight: 800; margin: 6px 2px 12px; letter-spacing: -0.01em; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--card);
  font-size: 13px; font-weight: 700; color: var(--text); white-space: nowrap;
}
.chip.is-active { background: var(--brand-grad); color: #fff; border-color: transparent; }

.loadmore {
  display: block; width: 100%; margin: 16px 0 4px;
  padding: 14px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--border);
  font-weight: 800; font-size: 14.5px; color: var(--brand-2);
}
.empty { text-align: center; color: var(--hint); padding: 46px 20px; font-size: 15px; }

/* ------------------------------ categories -------------------------- */
.cat-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.cat {
  position: relative; overflow: hidden;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 0; text-align: left;
}
.cat__img { aspect-ratio: 16/10; width: 100%; object-fit: cover; background: var(--bg-2); }
.cat__img--ph { display: flex; align-items: center; justify-content: center; font-size: 30px; color: var(--brand-2); aspect-ratio: 16/10; background: var(--bg-2); }
.cat__name { padding: 10px 12px; font-weight: 800; font-size: 14px; }

/* -------------------------------- cart ------------------------------ */
.cart-line {
  display: flex; gap: 12px; align-items: center;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px; margin-bottom: 10px;
}
.cart-line__img { width: 62px; height: 62px; object-fit: contain; background: #fff; border-radius: 10px; flex: 0 0 62px; }
.cart-line__info { flex: 1; min-width: 0; }
.cart-line__title { font-size: 13.5px; font-weight: 700; line-height: 1.3; }
.cart-line__variant { font-size: 12px; color: var(--hint); margin-top: 2px; }
.cart-line__price { font-size: 14px; font-weight: 800; margin-top: 4px; color: var(--brand-2); }
.qty { display: inline-flex; align-items: center; gap: 2px; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.qty button { width: 34px; height: 34px; font-size: 18px; font-weight: 800; color: var(--brand-2); }
.qty span { min-width: 26px; text-align: center; font-weight: 800; font-size: 14px; }
.cart-line__remove { color: var(--hint); font-size: 20px; padding: 8px; }

.cart-summary {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-top: 14px;
}
.cart-summary__row { display: flex; justify-content: space-between; font-size: 15px; font-weight: 700; }
.cart-summary__row b { font-size: 19px; font-weight: 900; }
.cart-summary__note { font-size: 12px; color: var(--hint); margin-top: 8px; line-height: 1.45; }
.btn-primary {
  display: block; width: 100%; margin-top: 14px;
  background: var(--brand-grad); color: #fff;
  font-weight: 800; font-size: 16.5px;
  padding: 16px; border-radius: 999px; text-align: center;
  box-shadow: 0 10px 24px rgba(0,103,184,.35);
  transition: transform .15s ease, opacity .15s ease;
}
.btn-primary:active { transform: scale(.97); }
.btn-primary[disabled] { opacity: .55; }
.btn-secondary {
  display: block; width: 100%; margin-top: 10px;
  background: var(--card); color: var(--brand-2);
  border: 1.5px solid var(--brand-2);
  font-weight: 800; font-size: 15px;
  padding: 14px; border-radius: 999px; text-align: center;
}

/* ------------------------------ support ------------------------------ */
.support { text-align: center; padding: 26px 8px 10px; }
.support__logo { width: 110px; height: 110px; margin: 0 auto 14px; border-radius: 50%; object-fit: contain; }
.support h2 { font-size: 21px; font-weight: 800; margin-bottom: 8px; }
.support p { color: var(--hint); font-size: 14.5px; line-height: 1.55; max-width: 320px; margin: 0 auto 18px; }
.support small { display: block; color: var(--hint); font-size: 12px; margin-top: 16px; }

/* ------------------------------- modal ------------------------------- */
.modal { position: fixed; inset: 0; z-index: 60; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(6,16,32,.55); }
.modal__sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 88vh; overflow-y: auto;
  background: var(--card);
  border-radius: 22px 22px 0 0;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  animation: sheetIn .25s ease;
}
@keyframes sheetIn { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.modal__close {
  position: absolute; top: 10px; right: 12px;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--bg-2); color: var(--hint); font-size: 20px; z-index: 2;
}
.pmodal__img { width: 100%; max-height: 250px; object-fit: contain; background: #fff; border-radius: 14px; margin-bottom: 12px; }
.pmodal__title { font-size: 18px; font-weight: 800; line-height: 1.3; padding-right: 30px; }
.pmodal__stock { font-size: 12.5px; font-weight: 800; margin: 6px 0 8px; }
.pmodal__stock.ok { color: #1a9e4b; }
.pmodal__stock.ko { color: var(--danger); }
.pmodal__price { display: flex; align-items: baseline; gap: 8px; margin-bottom: 10px; }
.pmodal__price .price { font-size: 24px; }
.pmodal__save { background: #e6f4ea; color: #14532d; font-size: 12px; font-weight: 800; padding: 4px 9px; border-radius: 8px; }
.pmodal__desc { font-size: 14px; line-height: 1.55; color: var(--hint); margin-bottom: 14px; }
.pmodal__label { font-size: 13px; font-weight: 800; margin-bottom: 6px; }
.pmodal__variants { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.vchip {
  padding: 9px 13px; border-radius: 12px; font-size: 13px; font-weight: 700;
  border: 1.5px solid var(--border); background: var(--bg); color: var(--text);
}
.vchip.is-active { border-color: var(--brand-2); background: color-mix(in srgb, var(--brand-2) 12%, transparent); color: var(--brand-2); }
.vchip[disabled] { opacity: .4; text-decoration: line-through; }

/* ------------------------------- toast ------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + 18px);
  transform: translateX(-50%);
  background: #16233b; color: #fff;
  font-size: 14px; font-weight: 700;
  padding: 12px 20px; border-radius: 999px;
  box-shadow: 0 10px 30px rgba(0,0,0,.3);
  z-index: 70; white-space: nowrap;
  animation: toastIn .2s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ------------------------------ bottom nav --------------------------- */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--card);
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: repeat(4, 1fr);
}
.bottomnav__item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 700; color: var(--hint); position: relative;
}
.bottomnav__item svg { width: 22px; height: 22px; }
.bottomnav__item.is-active { color: var(--brand-2); }
.bottomnav__badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 800;
  min-width: 17px; height: 17px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}

/* ------------------------------- loader ------------------------------ */
.loader { display: flex; justify-content: center; padding: 30px; }
.loader[hidden], .toast[hidden], .modal[hidden] { display: none !important; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3.5px solid var(--border); border-top-color: var(--brand-2);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------- category groups -------------------------- */
.cat-group { margin-bottom: 22px; }
.cat-group__title {
  display: flex; align-items: center; gap: 8px;
  font-size: 16px; font-weight: 800;
  margin: 0 2px 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid color-mix(in srgb, var(--brand-2) 25%, transparent);
}
.cat-group__title span { font-size: 18px; }

/* --------------------- category chips (Home) ------------------------ */
.chips--cats { padding-bottom: 12px; }
.chip--cat {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 14px;
  border: 1px solid color-mix(in srgb, var(--brand-2) 30%, transparent);
  background: color-mix(in srgb, var(--brand-2) 8%, var(--card));
}
.chip--cat img { width: 18px; height: 18px; object-fit: contain; }
.chip--cat b { font-weight: 700; }

/* ----------------------- group bottom sheet ------------------------- */
.sheet-ico { width: 22px; height: 22px; object-fit: contain; vertical-align: -3px; margin-right: 4px; }
.sheet-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.sheet-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 14px;
  font-size: 15px; font-weight: 700; text-align: left;
}
.sheet-item:active { background: var(--bg-2); }
.sheet-item img { width: 34px; height: 34px; object-fit: cover; border-radius: 8px; flex: 0 0 34px; background: #fff; }
.sheet-item__name { flex: 1; }
.sheet-item__arrow { color: var(--hint); font-size: 20px; }

/* --------------------------- promo badges --------------------------- */
.promo-badges { display: flex; flex-direction: column; gap: 8px; padding-bottom: 12px; }
.pbadge {
  display: block; width: 100%;
  text-align: center;
  font-size: 13px; font-weight: 800;
  padding: 10px 14px; border-radius: 12px;
  background: color-mix(in srgb, #1a9e4b 12%, var(--card));
  border: 1px solid color-mix(in srgb, #1a9e4b 35%, transparent);
  color: var(--text);
}
.pbadge--code {
  background: color-mix(in srgb, var(--brand-2) 12%, var(--card));
  border-color: color-mix(in srgb, var(--brand-2) 40%, transparent);
  cursor: pointer;
}
.pbadge--code:active { transform: scale(.98); }

/* --------------------------- warranty row --------------------------- */
.warranty-row {
  display: flex; align-items: center; gap: 10px;
  background: color-mix(in srgb, #1a9e4b 8%, var(--card));
  border: 1px solid color-mix(in srgb, #1a9e4b 30%, transparent);
  border-radius: var(--radius);
  padding: 13px 14px; margin-top: 4px;
  font-size: 13.5px; font-weight: 700; cursor: pointer;
}
.warranty-row input { width: 19px; height: 19px; accent-color: #1a9e4b; flex: 0 0 auto; }
.warranty-row__ic { font-size: 18px; }
.warranty-row__t { flex: 1; line-height: 1.35; }
.warranty-row b { color: #1a9e4b; white-space: nowrap; }

/* ---------------------------- bundle card --------------------------- */
.bundle-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.bundle-card p { font-size: 14px; line-height: 1.5; color: var(--hint); margin-bottom: 12px; }
.bundle-card .btn-primary { margin-top: 0; }
