#sbpcb-builder {
  max-width: 1100px;
  margin: 0 auto;
}

.sbpcb-page-lead {
  font-size: 0.9rem;
  margin: -0.25rem 0 1rem;
  line-height: 1.45;
}

.sbpcb-component {
  margin-bottom: 12px;
}

/* Desktop: riga componenti (layout originale) */
.sbpcb-row {
  min-height: 88px;
  padding: 10px 8px;
  border: 1px solid #e5e5e5;
  border-radius: 0.25rem;
  background: var(--bs-gray-100, #f8f9fa);
  cursor: pointer;
}

.sbpcb-title {
  font-weight: 700;
  font-size: 1.25rem;
}

.sbpcb-chevron {
  display: none;
}

.sbpcb-selected-name {
  font-weight: 600;
}

.sbpcb-qty {
  width: 4.5rem;
  text-align: right;
}

.sbpcb-selected-price {
  font-weight: 700;
}

.sbpcb-products-panel {
  display: none;
}

.sbpcb-component.open .sbpcb-products-panel {
  display: block;
}

.sbpcb-products-hint {
  display: none;
}

.sbpcb-products {
  display: none;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}

.sbpcb-component.open .sbpcb-products {
  display: grid;
}

/* Schede prodotto — base desktop */
.sbpcb-card {
  position: relative;
  border: 1px solid #d1d5db;
  padding: 10px;
  cursor: pointer;
  background: #fff;
  border-radius: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.sbpcb-card__check {
  display: none;
}

.sbpcb-card.selected .sbpcb-card__check {
  display: none;
}

.sbpcb-card__media {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 90px;
}

.sbpcb-card__media img {
  max-width: 120px;
  max-height: 90px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.sbpcb-card__media-placeholder {
  font-size: 2rem;
  color: #94a3b8;
}

.sbpcb-card__body {
  flex: 1 1 auto;
}

.sbpcb-card__footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
}

.sbpcb-card.selected {
  border-color: #0d6efd;
  box-shadow: 0 0 0 2px rgba(13, 110, 253, 0.22);
}

.sbpcb-card .sbpcb-card-qtywrap {
  position: absolute;
  right: 8px;
  bottom: 8px;
  background: rgba(255, 255, 255, 0.95);
  padding: 4px;
  border: 1px solid #ddd;
  border-radius: 0.25rem;
}

.sbpcb-card .sbpcb-card-qty {
  width: 4rem;
  text-align: right;
}

.sbpcb-name {
  font-size: 0.92rem;
  line-height: 1.35;
  font-weight: 600;
}

.sbpcb-price {
  font-weight: 700;
  color: #0d6efd;
}

.sbpcb-availability-badge {
  font-size: 0.75rem;
  font-weight: 600;
}

.sbpcb-availability.ok,
.sbpcb-availability-badge.ok {
  color: #198754;
}

.sbpcb-availability.ko,
.sbpcb-availability-badge.ko {
  color: #dc3545;
}

.sbpcb-thumb {
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 0.25rem;
}

.sbpcb-component.sbpcb-error .sbpcb-row {
  border-color: #dc3545;
  box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.2);
}

.sbpcb-card.incompatible {
  opacity: 0.45;
}

.sbpcb-card.disabled {
  pointer-events: none;
}

#sbpcb-builder .sbpcb-total {
  position: sticky;
  bottom: 0;
  z-index: 100;
  background: #fff;
  border-top: 3px solid #0d6efd;
  box-shadow: 0 -8px 22px rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

#sbpcb-builder #sbpcb-total-incl {
  font-size: 1.35rem;
  font-weight: 800;
  color: #0d6efd;
}

#sbpcb-builder .sbpcb-total-cta {
  white-space: nowrap;
}

#sbpcb-builder-form {
  padding-bottom: 90px;
}

/* ========== Solo mobile: accordion + schede carousel ========== */
@media (max-width: 767.98px) {
  #sbpcb-builder-form {
    padding-bottom: calc(150px + env(safe-area-inset-bottom, 0px));
  }

  .sbpcb-row {
    min-height: 0;
    padding: 12px;
    cursor: pointer;
  }

  .sbpcb-row-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
  }

  .sbpcb-title {
    font-size: 1.1rem;
  }

  .sbpcb-chevron {
    display: inline-flex;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(106, 0, 255, 0.1);
    color: #6a00ff;
  }

  .sbpcb-chevron::before {
    content: "";
    display: block;
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    margin-top: -3px;
    transition: transform 0.2s ease;
  }

  .sbpcb-component.open .sbpcb-chevron::before {
    transform: rotate(-135deg);
    margin-top: 3px;
  }

  .sbpcb-selection {
    width: 100%;
  }

  .sbpcb-selected-name {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    white-space: normal;
  }

  .sbpcb-row-actions {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px dashed #dee2e6;
    width: 100%;
    justify-content: space-between !important;
  }

  .sbpcb-remove {
    min-width: 44px;
    min-height: 44px;
  }

  .sbpcb-products-panel {
    margin-top: 0.5rem;
    padding: 0.75rem 0 0.25rem;
    background: linear-gradient(180deg, #f1f5f9 0%, #f8fafc 100%);
    border-radius: 0.85rem;
    border: 1px solid #e2e8f0;
  }

  .sbpcb-products-hint {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.78rem;
    font-weight: 600;
    color: #64748b;
    margin: 0 0.85rem 0.65rem;
  }

  .sbpcb-products-hint__icon {
    flex-shrink: 0;
    width: 1.15rem;
    height: 1.15rem;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff0080 0%, #6a00ff 100%);
    opacity: 0.85;
    position: relative;
  }

  .sbpcb-products-hint__icon::before,
  .sbpcb-products-hint__icon::after {
    content: "";
    position: absolute;
    top: 50%;
    width: 5px;
    height: 5px;
    margin-top: -2.5px;
    border-top: 2px solid #fff;
    border-right: 2px solid #fff;
    transform: rotate(45deg);
  }

  .sbpcb-products-hint__icon::before {
    left: 2px;
    opacity: 0.5;
  }

  .sbpcb-products-hint__icon::after {
    right: 2px;
  }

  .sbpcb-component.open .sbpcb-products {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 14px;
    padding: 0 0.85rem 1rem;
    scroll-snap-type: x proximity;
    scroll-padding-inline: 0.85rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .sbpcb-component.open .sbpcb-products::-webkit-scrollbar {
    display: none;
  }

  .sbpcb-card {
    flex: 0 0 clamp(260px, 72vw, 300px);
    scroll-snap-align: center;
    padding: 0;
    min-height: 280px;
    overflow: hidden;
    border: 2px solid #e2e8f0;
    box-shadow: 0 4px 14px rgba(15, 23, 42, 0.07);
  }

  .sbpcb-card:active {
    transform: scale(0.985);
  }

  .sbpcb-card__check {
    display: block;
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff0080 0%, #6a00ff 100%);
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.2s, transform 0.2s;
  }

  .sbpcb-card__check::after {
    content: "";
    position: absolute;
    left: 9px;
    top: 5px;
    width: 6px;
    height: 11px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
  }

  .sbpcb-card.selected .sbpcb-card__check {
    opacity: 1;
    transform: scale(1);
  }

  .sbpcb-card__media {
    min-height: 148px;
    padding: 1.1rem;
    background: linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
    border-bottom: 1px solid #eef2f7;
  }

  .sbpcb-card__media img {
    max-width: 100%;
    max-height: 128px;
  }

  .sbpcb-card__body {
    padding: 0.85rem 1rem 0.35rem;
  }

  .sbpcb-card__footer {
    padding: 0 1rem 1rem;
  }

  .sbpcb-name {
    font-size: 0.88rem;
    -webkit-line-clamp: 4;
  }

  .sbpcb-price {
    font-size: 1.1rem;
    color: #0f172a;
  }

  .sbpcb-availability-badge {
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }

  .sbpcb-availability-badge.ok {
    background: #dcfce7;
    color: #166534;
  }

  .sbpcb-availability-badge.ko {
    background: #fee2e2;
    color: #991b1b;
  }

  .sbpcb-card.selected {
    border-color: #6a00ff;
    box-shadow: 0 10px 28px rgba(106, 0, 255, 0.2);
  }

  .sbpcb-card .sbpcb-card-qtywrap {
    left: 1rem;
    right: 1rem;
    bottom: 3.25rem;
    padding: 0.45rem 0.55rem;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.08);
  }

  .sbpcb-card .sbpcb-card-qtywrap::before {
    content: "Qtà";
    font-size: 0.72rem;
    font-weight: 700;
    color: #64748b;
  }

  #sbpcb-builder .sbpcb-total {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    border-radius: 0;
    flex-direction: column;
    align-items: stretch;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom, 0px));
  }

  #sbpcb-builder .sbpcb-total-cta {
    width: 100%;
    min-height: 48px;
    white-space: normal;
  }
}

/* Backoffice */
#sbpcbCategoryModal.open {
  display: block;
  position: fixed;
  top: 6%;
  left: 50%;
  transform: translateX(-50%);
  width: 80%;
  max-width: 900px;
  z-index: 9999;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 0.25rem;
}

#sbpcb-components-table tr.sbpcb-drag-over td {
  background: #e8f0fe;
  border-top: 2px solid #0d6efd;
}
