/* NB4 Super Products Grid — Frontend */

/* Layout generale wrapper + sidebar */
.nb4-spg-wrap {
  --nb4-spg-sidebar-width: 280px;
  display: grid;
  grid-template-columns: minmax(0, var(--nb4-spg-sidebar-width)) minmax(0, 1fr);
  gap: 24px;
  background: transparent;
  align-items: start;
}

.nb4-spg-wrap:not(.sidebar-left) {
  grid-template-columns: minmax(0, 1fr);
}

.nb4-spg-wrap .nb4-spg-sidebar {
  --nb4-spg-sidebar-pad-x: 16px;
  --nb4-spg-cat-hover-pt: 0px;
  --nb4-spg-cat-hover-pr: 0px;
  --nb4-spg-cat-hover-pb: 0px;
  --nb4-spg-cat-hover-pl: 0px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  background: #fff;
  padding: 16px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow-x: hidden;
}

.nb4-spg-wrap .nb4-spg-main {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}


@media (min-width: 1025px) {
  .nb4-spg-wrap.nb4-spg-sidebar-sticky .nb4-spg-sidebar {
    position: sticky;
    top: var(--nb4-spg-sidebar-sticky-top, 24px);
    align-self: start;
    max-height: calc(100vh - var(--nb4-spg-sidebar-sticky-top, 24px) - 24px);
    overflow-y: auto;
  }
}

/* Filtri base */
.nb4-spg-wrap .nb4-spg-filter {
  margin-bottom: 16px;
}

.nb4-spg-wrap .nb4-spg-filter label {
  display: block;
  margin: 6px 0;
}

.nb4-spg-wrap .nb4-spg-range {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nb4-spg-wrap .nb4-spg-range input {
  width: 100%;
}

.nb4-spg-wrap .nb4-spg-input,
.nb4-spg-wrap .nb4-spg-sidebar input[type="number"],
.nb4-spg-wrap .nb4-spg-sidebar select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
}

/* Pulsante reset */
.nb4-spg-wrap .nb4-spg-reset {
  margin-top: 8px;
  display: inline-block;
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  background: #f3f4f6;
  cursor: pointer;
}

/* Toolbar (conteggio, orderby) */
.nb4-spg-wrap .nb4-spg-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

/* GRID PRODOTTI */
.nb4-spg-main .nb4-spg-grid {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: repeat(var(--nb4-cols, 4), minmax(0, 1fr));
  gap: var(--nb4-gap, 20px);
}

/* Modalità dichiarativa */
.nb4-spg-grid[data-mode="grid"],
.nb4-spg-grid[data-mode="masonry"] {
  display: grid;
  grid-template-columns: repeat(var(--nb4-cols, 4), minmax(0, 1fr));
  gap: var(--nb4-gap, 20px);
}

/* Card prodotto */
.nb4-spg-card {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}

.nb4-spg-card-inner {
  padding: 12px;
  display: flex;
  flex-direction: column;
}

/* Immagine / thumb */
.nb4-spg-thumb-wrap {
  display: block;
  position: relative;
}

.nb4-spg-thumb-frame {
  position: relative;
  width: 100%;
  aspect-ratio: var(--nb4-ratio, 1/1);
  overflow: hidden;
}

.nb4-spg-thumb-frame .nb4-spg-thumb {
  width: 100%;
  height: 100%;
  object-fit: var(--nb4-fit, cover);
  display: block;
}

/* Overlay su hover */
.nb4-spg-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.55);
  color: #fff;
  opacity: 0;
  transition: opacity .2s ease;
  padding: 12px;
  text-align: center;
}

.nb4-spg-thumb-wrap:hover .nb4-spg-overlay {
  opacity: 1;
}

.nb4-spg-title-static,
.nb4-spg-price-static {
  margin: 6px 0;
}

/* Allineamenti */
.nb4-spg-wrap[data-align="left"] .nb4-spg-card-inner {
  text-align: left;
  align-items: flex-start;
}

.nb4-spg-wrap[data-align="center"] .nb4-spg-card-inner {
  text-align: center;
  align-items: center;
}

.nb4-spg-wrap[data-align="right"] .nb4-spg-card-inner {
  text-align: right;
  align-items: flex-end;
}

.nb4-spg-wrap[data-v-align="top"] .nb4-spg-card-inner { justify-content: flex-start; }
.nb4-spg-wrap[data-v-align="middle"] .nb4-spg-card-inner { justify-content: center; }
.nb4-spg-wrap[data-v-align="bottom"] .nb4-spg-card-inner { justify-content: flex-end; }

.nb4-spg-wrap[data-overlay-align="left"] .nb4-spg-overlay { text-align: left; align-items: flex-start; }
.nb4-spg-wrap[data-overlay-align="center"] .nb4-spg-overlay { text-align: center; align-items: center; }
.nb4-spg-wrap[data-overlay-align="right"] .nb4-spg-overlay { text-align: right; align-items: flex-end; }

/* Bottone Scopri di più */
.nb4-spg-readmore {
  display: inline-block;
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  background: #111827;
  color: #fff;
  text-decoration: none;
  transition: opacity .15s ease;
}

.nb4-spg-readmore:hover { opacity: .9; }

/* Visibilità titolo/prezzo */
.nb4-spg-wrap[data-show-title="visible"] .nb4-spg-title-static { display: block; }
.nb4-spg-wrap[data-show-title="hover"]   .nb4-spg-title-static { display: none; }
.nb4-spg-wrap[data-show-title="hidden"]  .nb4-spg-title-static { display: none; }

.nb4-spg-wrap[data-show-title="visible"] .nb4-spg-overlay .nb4-spg-title { display: none; }
.nb4-spg-wrap[data-show-title="hover"]   .nb4-spg-overlay .nb4-spg-title { display: block; }
.nb4-spg-wrap[data-show-title="hidden"]  .nb4-spg-overlay .nb4-spg-title { display: none; }

.nb4-spg-wrap[data-show-price="visible"] .nb4-spg-price-static { display: block; }
.nb4-spg-wrap[data-show-price="hover"]   .nb4-spg-price-static { display: none; }
.nb4-spg-wrap[data-show-price="hidden"]  .nb4-spg-price-static { display: none; }

.nb4-spg-wrap[data-show-price="visible"] .nb4-spg-overlay .nb4-spg-price { display: none; }
.nb4-spg-wrap[data-show-price="hover"]   .nb4-spg-overlay .nb4-spg-price { display: block; }
.nb4-spg-wrap[data-show-price="hidden"]  .nb4-spg-overlay .nb4-spg-price { display: none; }

/* Nascondi readmore quando disabilitato */
.nb4-spg-wrap[data-read-more="no"] .nb4-spg-readmore { display: none !important; }

/* Responsive layout */
@media (max-width: 1024px) {
  .nb4-spg-wrap { grid-template-columns: minmax(0, 1fr); }
  .nb4-spg-wrap .nb4-spg-sidebar { order: 1; width: 100% !important; }
  .nb4-spg-wrap .nb4-spg-main { order: 2; }
}

/* CATEGORY TREE */
.nb4-spg-filter-cats {
  border-bottom: 1px solid #e5e7eb;
  padding-bottom: 10px;
  margin-bottom: 18px;
}

.nb4-spg-cat-tree .nb4-spg-cat-level {
  list-style: none;
  margin: 0;
  padding-left: 0;
}

.nb4-spg-cat-item { margin-bottom: 4px; }

.nb4-spg-cat-row {
  --nb4-spg-cat-bleed-left: var(--nb4-spg-sidebar-pad-x, 16px);
  --nb4-spg-cat-bleed-right: var(--nb4-spg-sidebar-pad-x, 16px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: auto;
  box-sizing: border-box;
  margin-left: calc(-1 * var(--nb4-spg-cat-bleed-left));
  margin-right: calc(-1 * var(--nb4-spg-cat-bleed-right));
  padding: var(--nb4-spg-cat-hover-pt) calc(var(--nb4-spg-cat-hover-pr) + var(--nb4-spg-cat-bleed-right)) var(--nb4-spg-cat-hover-pb) calc(var(--nb4-spg-cat-hover-pl) + var(--nb4-spg-cat-bleed-left));
  transition: background .2s ease, color .2s ease;
}

.nb4-spg-cat-children > .nb4-spg-cat-item > .nb4-spg-cat-row {
  --nb4-spg-cat-bleed-left: calc(var(--nb4-spg-sidebar-pad-x, 16px) + 18px);
}

.nb4-spg-cat-children .nb4-spg-cat-children > .nb4-spg-cat-item > .nb4-spg-cat-row {
  --nb4-spg-cat-bleed-left: calc(var(--nb4-spg-sidebar-pad-x, 16px) + 36px);
}

.nb4-spg-cat-children .nb4-spg-cat-children .nb4-spg-cat-children > .nb4-spg-cat-item > .nb4-spg-cat-row {
  --nb4-spg-cat-bleed-left: calc(var(--nb4-spg-sidebar-pad-x, 16px) + 54px);
}

.nb4-spg-cat-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
  cursor: pointer;
  border: none !important;
  padding: 0;
  margin: 0;
  background: transparent;
  box-shadow: none !important;
  font: inherit;
  color: inherit;
}

.nb4-spg-cat-macro {
  border: none !important;
  background: none;
  box-shadow: none !important;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.nb4-spg-cat-macro .nb4-spg-cat-name { font-weight: 600; }

.nb4-spg-cat-name { font-size: 13px; transition: color .2s ease; }

.nb4-spg-cat-leaf input[type="checkbox"] {
  margin-right: 6px;
  margin-left: 0;
}

.nb4-spg-cat-toggle {
  border: none !important;
  background: none !important;
  box-shadow: none !important;
  cursor: pointer;
  padding: 0 !important;
  margin: 0 0 0 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  font: inherit;
  color: inherit;
  -webkit-appearance: none;
  appearance: none;
}

.nb4-spg-cat-macro:focus,
.nb4-spg-cat-macro:active,
.nb4-spg-cat-toggle:focus,
.nb4-spg-cat-toggle:active {
  outline: none;
  background: none !important;
  box-shadow: none !important;
  border: none !important;
}

.nb4-spg-cat-toggle-icon {
  font-size: 14px;
  transition: color .2s ease;
  line-height: 1;
  display: inline-block;
  width: auto;
  height: auto;
  border: 0;
  transform: none;
}

.nb4-spg-cat-toggle-icon-default { display: none !important; border: 0 !important; }

.nb4-spg-cat-toggle-icon-open { display: none; }
.nb4-spg-cat-toggle[aria-expanded="true"] .nb4-spg-cat-toggle-icon-open { display: inline-block; }
.nb4-spg-cat-toggle[aria-expanded="true"] .nb4-spg-cat-toggle-icon-closed { display: none; }

.nb4-spg-cat-children {
  margin-left: 14px;
  margin-top: 4px;
  padding-left: 4px;
  border-left: 1px dashed #e5e7eb;
}

.nb4-spg-sidebar .nb4-spg-filter strong {
  font-size: 13px;
  text-transform: none;
  letter-spacing: 0;
  display: block;
  margin-bottom: 4px;
}

.nb4-spg-sidebar .nb4-spg-filter strong::before { content: none !important; }
.nb4-spg-sidebar .nb4-spg-filter label { font-size: 13px; }
.nb4-spg-sidebar .nb4-spg-cat-toggle-icon { color: inherit; }

/* SEARCH SUGGESTIONS */
.nb4-spg-search-wrap { position: relative; }

.nb4-spg-suggestions {
  position: absolute;
  z-index: 30;
  left: 0;
  right: 0;
  top: 100%;
  margin-top: 4px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  max-height: 260px;
  overflow-y: auto;
  box-shadow: 0 10px 25px rgba(15,23,42,.15);
  display: none;
}

.nb4-spg-suggest-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  text-decoration: none;
  color: inherit;
}

.nb4-spg-suggest-item:hover { background: #f3f4f6; }

.nb4-spg-suggest-thumb img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
}

.nb4-spg-suggest-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nb4-spg-suggest-title { font-size: 14px; font-weight: 500; }
.nb4-spg-suggest-price { font-size: 13px; opacity: .8; }

/* Forza griglia */
.nb4-spg-main .nb4-spg-grid {
  width: 100% !important;
  display: grid !important;
  grid-template-columns: repeat(var(--nb4-cols, 4), minmax(0, 1fr)) !important;
  gap: var(--nb4-gap, 20px) !important;
}

/* TOP LEVEL senza figli = niente checkbox */
.nb4-spg-cat-tree > .nb4-spg-cat-level > .nb4-spg-cat-item:not(.has-children)
> .nb4-spg-cat-row .nb4-spg-cat-label input[type="checkbox"]{
  display: none !important;
}

.nb4-spg-cat-tree > .nb4-spg-cat-level > .nb4-spg-cat-item:not(.has-children)
> .nb4-spg-cat-row .nb4-spg-cat-label{
  gap: 0 !important;
}

/* Font e stile identico alle macro Elementor (16px) */
.elementor .nb4-spg-cat-tree
> .nb4-spg-cat-level
> .nb4-spg-cat-item:not(.has-children)
> .nb4-spg-cat-row
> .nb4-spg-cat-label
> .nb4-spg-cat-name{
  font-size: 16px !important;
  font-weight: 600 !important;
}

/* -------------------------------
   LOADER SOLO SULLA GRIGLIA (STICKY NEL VIEWPORT)
   ------------------------------- */

.nb4-spg-grid{
  position: relative;
}

/* il JS imposta top/left/width/height per “agganciarsi” alla griglia visibile */
.nb4-spg-loader{
  position: fixed;              /* ✅ sempre visibile nel viewport */
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,.65);
  z-index: 9999;
  pointer-events: none;         /* ✅ non blocca click */
  will-change: top,left,width,height;
}

/* Mostra quando la griglia è in loading */
.nb4-spg-grid.nb4-spg-loading .nb4-spg-loader{
  display: flex;
}

.nb4-spg-spinner{
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(17,24,39,.2);
  border-top-color: rgba(17,24,39,.85);
  animation: nb4spgSpin .75s linear infinite;
}

@keyframes nb4spgSpin{
  to { transform: rotate(360deg); }
}
/* Suggerimenti ricerca: layout verticale */
.nb4-spg-suggest-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 6px;
}

.nb4-spg-suggest-thumb {
    width: 60px;
    height: auto;
    margin: 0;
}

.nb4-spg-suggest-thumb img {
    width: 100%;
    height: auto;
    display: block;
}

.nb4-spg-suggest-title {
    font-size: 13px;
    line-height: 1.3;
}

/* Controlli tipografici separati dei filtri */
.nb4-spg-sidebar .nb4-spg-filter-title,
.nb4-spg-sidebar .nb4-spg-filter > strong {
  display: block;
}

.nb4-spg-sidebar .nb4-spg-filter-option,
.nb4-spg-sidebar .nb4-spg-tag-option,
.nb4-spg-sidebar .nb4-spg-brand-option,
.nb4-spg-sidebar .nb4-spg-attr-option {
  display: block;
}
