[data-sofa-builder] {
  --pcb-primary: #2563eb;
  --pcb-bg: #ffffff;
  --pcb-surface: #f3f4f6;
  --pcb-text: #111827;
  --pcb-muted: #6b7280;
  --pcb-danger: #dc2626;
  --pcb-success: #16a34a;
  --pcb-success-bg: #f0fdf4;
  --pcb-radius: 8px;
  --pcb-font: inherit;

  display: block;
  font-family: var(--pcb-font);
  color: var(--pcb-text);
  box-sizing: border-box;
}

[data-sofa-builder] * {
  box-sizing: border-box;
}

[data-sofa-builder] button,
[data-sofa-builder] input,
[data-sofa-builder] select {
  font-family: inherit;
}

.pcb-shell {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 300px;
  gap: 1.5rem;
  align-items: start;
}

/* ── Sidebar izquierda ────────────────────────────────────────────────── */

.pcb-sidebar {
  background: var(--pcb-bg);
  border-radius: var(--pcb-radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  position: sticky;
  top: 1rem;
}

.pcb-sidebar-head h2 {
  margin: 0 0 0.25rem;
  font-size: 1.25rem;
}

.pcb-sidebar-head p {
  margin: 0 0 1rem;
  color: var(--pcb-muted);
  font-size: 0.85rem;
}

.pcb-sidebar-step {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  border-radius: var(--pcb-radius);
  color: var(--pcb-muted);
  font-size: 0.875rem;
}

.pcb-sidebar-step-done {
  color: var(--pcb-text);
  cursor: pointer;
}

.pcb-sidebar-step-done:hover {
  background: var(--pcb-surface);
}

.pcb-sidebar-step-current {
  color: var(--pcb-text);
  background: var(--pcb-surface);
  font-weight: 600;
}

.pcb-sidebar-icon {
  flex: 0 0 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  background: var(--pcb-bg);
  border: 1px solid var(--pcb-muted);
}

.pcb-sidebar-step-done .pcb-sidebar-icon {
  background: var(--pcb-primary);
  border-color: var(--pcb-primary);
  color: #fff;
}

.pcb-sidebar-step-current .pcb-sidebar-icon {
  border-color: var(--pcb-primary);
  color: var(--pcb-primary);
}

.pcb-sidebar-step-locked {
  opacity: 0.6;
}

.pcb-sidebar-help {
  margin-top: 1.25rem;
  padding: 0.9rem;
  background: var(--pcb-surface);
  border-radius: var(--pcb-radius);
  display: flex;
  gap: 0.6rem;
  font-size: 0.8rem;
  color: var(--pcb-muted);
}

/* ── Columna central ──────────────────────────────────────────────────── */

.pcb-main {
  min-width: 0;
}

.pcb-content {
  background: var(--pcb-bg);
  border-radius: var(--pcb-radius);
  padding: 1.5rem;
}

.pcb-step-pill {
  display: inline-block;
  background: #eef2ff;
  color: var(--pcb-primary);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  margin-bottom: 0.75rem;
}

.pcb-step-title {
  margin: 0 0 0.4rem;
  font-size: 1.5rem;
}

.pcb-step-desc {
  margin: 0 0 1.25rem;
  color: var(--pcb-muted);
}

.pcb-loading,
.pcb-empty,
.pcb-error {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--pcb-muted);
}

.pcb-error {
  color: var(--pcb-danger);
}

/* ── Toolbar ───────────────────────────────────────────────────────────── */

.pcb-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

/* flex-grow alto en vez de un min-width fijo: sigue siendo el más ancho
   del toolbar, pero sin un piso duro que fuerce el wrap del resto cuando
   la columna central es angosta (con min-width:50% + ancho del select +
   paginador, en muchos anchos de pantalla ya no entraba todo junto). */
.pcb-search {
  flex: 3 1 140px;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: var(--pcb-radius);
}

.pcb-sort {
  flex: 0 1 140px;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid #d1d5db;
  border-radius: var(--pcb-radius);
  text-overflow: ellipsis;
}

/* Paginador como flechas compactas dentro del toolbar (no más bloque
   aparte debajo de la grilla). */
.pcb-pager-inline {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.pcb-pager-arrow {
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 50%;
  border: 1px solid var(--pcb-primary);
  background: var(--pcb-bg);
  color: var(--pcb-primary);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.pcb-pager-arrow:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pcb-pager-info {
  color: var(--pcb-muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

/* ── Gauge de consumo (paso fuente) ───────────────────────────────────── */

.pcb-gauge {
  margin-bottom: 1.25rem;
  padding: 1rem;
  background: var(--pcb-surface);
  border-radius: var(--pcb-radius);
}

.pcb-gauge-label {
  font-size: 0.85rem;
  color: var(--pcb-muted);
  margin-bottom: 0.5rem;
}

.pcb-gauge-label strong {
  color: var(--pcb-text);
}

.pcb-gauge-bar {
  height: 10px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
}

.pcb-gauge-fill {
  height: 100%;
  border-radius: 999px;
}

.pcb-gauge-ok {
  background: var(--pcb-success);
}

.pcb-gauge-low {
  background: var(--pcb-danger);
}

/* ── Grilla de productos ──────────────────────────────────────────────── */

.pcb-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.9rem;
  margin-bottom: 1.25rem;
}

.pcb-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--pcb-bg);
  border: 2px solid #e5e7eb;
  border-radius: var(--pcb-radius);
  padding: 0;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.pcb-card:hover:not(:disabled) {
  border-color: var(--pcb-primary);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08);
}

.pcb-card.is-selected {
  border-color: var(--pcb-primary);
}

.pcb-card:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pcb-badge {
  position: absolute;
  top: 0.6rem;
  left: 0.6rem;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  color: #fff;
  z-index: 1;
}

.pcb-badge-recommended {
  background: var(--pcb-primary);
}

.pcb-badge-bestseller {
  background: var(--pcb-success);
}

.pcb-card-image {
  position: relative;
  height: 140px;
  background: var(--pcb-surface);
  display: flex;
  align-items: center;
  justify-content: center;
}

.pcb-card-image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 0.6rem;
}

.pcb-card-body {
  padding: 0.9rem;
}

.pcb-card-name {
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.pcb-card-specs {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
  font-size: 0.78rem;
  color: var(--pcb-muted);
}

.pcb-card-stock {
  font-size: 0.75rem;
  margin-bottom: 0.35rem;
}

.pcb-card-stock-in {
  color: var(--pcb-success);
}

.pcb-card-stock-out {
  color: var(--pcb-danger);
}

.pcb-card-price {
  font-weight: 700;
  color: var(--pcb-text);
}

.pcb-card-installment {
  font-size: 0.75rem;
  color: var(--pcb-muted);
}

/* ── Cards multi-select (paso Almacenamiento con el setting activo) ─────── */

.pcb-card-multi {
  cursor: default;
}

.pcb-qty-stepper {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
}

.pcb-qty-stepper button {
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  border: 1px solid var(--pcb-primary);
  background: var(--pcb-bg);
  color: var(--pcb-primary);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.pcb-qty-stepper button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pcb-qty-stepper span {
  min-width: 1rem;
  text-align: center;
  font-weight: 600;
}

.pcb-card-disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Overlay de cantidad sobre la imagen (RAM y Almacenamiento multi) ──── */

.pcb-card-qty-overlay {
  position: absolute;
  z-index: 1;
  left: 50%;
  bottom: 0.5rem;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.95);
  border-radius: 999px;
  padding: 0.2rem 0.5rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}

.pcb-qty-stepper-sm button {
  width: 1.4rem;
  height: 1.4rem;
  font-size: 0.8rem;
}

.pcb-qty-stepper-sm span {
  font-size: 0.8rem;
}

.pcb-card-add-overlay {
  border: none;
  background: var(--pcb-primary);
  color: #fff;
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.pcb-card-add-overlay:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pcb-context-banner {
  padding: 0.9rem 1rem;
  background: #eff6ff;
  border-radius: var(--pcb-radius);
  font-size: 0.85rem;
  margin-bottom: 1.25rem;
}

/* ── Paso marca ────────────────────────────────────────────────────────── */

.pcb-brand-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.pcb-brand-card {
  border: 2px solid #e5e7eb;
  border-radius: var(--pcb-radius);
  padding: 1.5rem;
  text-align: center;
}

.pcb-brand-card.is-selected {
  border-color: var(--pcb-primary);
}

.pcb-brand-name {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.pcb-brand-tagline {
  color: var(--pcb-muted);
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

/* ── Navegación ────────────────────────────────────────────────────────── */

.pcb-nav {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.pcb-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 1.2rem;
  border-radius: var(--pcb-radius);
  border: 1px solid var(--pcb-primary);
  background: var(--pcb-primary);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.pcb-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.pcb-btn-outline {
  background: transparent;
  color: var(--pcb-primary);
}

/* ── Resumen (paso final) ─────────────────────────────────────────────── */

.pcb-summary-table {
  margin-bottom: 1.25rem;
}

.pcb-summary-table-row {
  display: grid;
  grid-template-columns: 3rem 1fr auto auto;
  align-items: center;
  gap: 0.9rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--pcb-surface);
}

.pcb-summary-table-img {
  width: 3rem;
  height: 3rem;
  border-radius: 4px;
  object-fit: contain;
  background: var(--pcb-surface);
}

.pcb-summary-table-price {
  font-weight: 600;
  white-space: nowrap;
}

.pcb-summary-table-edit {
  font-size: 0.85rem;
  color: var(--pcb-primary);
  text-decoration: none;
  white-space: nowrap;
}

.pcb-summary-table-total {
  border-bottom: none;
  font-size: 1.15rem;
}

.pcb-summary-badges {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  padding: 1rem;
  background: var(--pcb-surface);
  border-radius: var(--pcb-radius);
  font-size: 0.8rem;
  margin-bottom: 1.25rem;
}

/* ── Sidebar derecha (resumen persistente) ────────────────────────────── */

.pcb-summary {
  background: var(--pcb-bg);
  border-radius: var(--pcb-radius);
  padding: 1.25rem;
  position: sticky;
  top: 1rem;
}

.pcb-summary h3 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.pcb-summary-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--pcb-surface);
}

.pcb-summary-total strong {
  font-size: 1.3rem;
  color: var(--pcb-primary);
}

.pcb-summary-installment {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--pcb-surface);
  font-size: 0.85rem;
}

.pcb-summary-installment-toggle {
  color: var(--pcb-primary);
  text-decoration: none;
  font-size: 0.8rem;
}

.pcb-summary-installment-detail {
  margin-top: 0.4rem;
  color: var(--pcb-muted);
  font-size: 0.8rem;
}

.pcb-summary-list {
  padding: 0.75rem 0;
}

.pcb-summary-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 0;
  font-size: 0.85rem;
}

.pcb-summary-row-label small {
  color: var(--pcb-muted);
}

.pcb-summary-row a {
  color: var(--pcb-primary);
  text-decoration: none;
  font-size: 0.8rem;
  white-space: nowrap;
}

.pcb-muted {
  color: var(--pcb-muted);
}

.pcb-summary-banner {
  display: flex;
  gap: 0.5rem;
  padding: 0.9rem;
  border-radius: var(--pcb-radius);
  font-size: 0.8rem;
  margin-top: 0.5rem;
}

.pcb-summary-banner-ok {
  background: var(--pcb-success-bg);
  color: #166534;
}

.pcb-summary-banner-empty {
  background: var(--pcb-surface);
  color: var(--pcb-muted);
}

/* ── Responsive ────────────────────────────────────────────────────────── */

@media (max-width: 960px) {
  .pcb-shell {
    grid-template-columns: 1fr;
  }

  .pcb-sidebar,
  .pcb-summary {
    position: static;
  }

  .pcb-sidebar {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .pcb-sidebar-head {
    flex-basis: 100%;
  }
}

@media (max-width: 720px) {
  .pcb-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .pcb-summary-table-row {
    grid-template-columns: 2.5rem 1fr;
    grid-template-areas: "img info" "img price" "img edit";
  }

  .pcb-summary-table-img { grid-area: img; }
  .pcb-summary-table-info { grid-area: info; }
  .pcb-summary-table-price { grid-area: price; }
  .pcb-summary-table-edit { grid-area: edit; }

  .pcb-grid {
    grid-template-columns: 1fr;
  }

  .pcb-search {
    flex-basis: 100%;
  }
}

/* ── Avisos de selecciones descartadas (R5) ────────────────────────────── */

.pcb-notices {
  margin-bottom: 1.25rem;
}

.pcb-notice {
  padding: 0.7rem 1rem;
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: var(--pcb-radius);
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
}
