#zelink-purchase-workflow-inline {
  display: block;
  width: 100%;
  min-width: 0;
}

.pw-shell {
  --pw-border: #e2e8f0;
  --pw-muted: #64748b;
  --pw-dark: #0f172a;
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
  padding: 0;
  color: var(--pw-dark);
}

.pw-shell *, .pw-shell *::before, .pw-shell *::after { box-sizing: border-box; }

.pw-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
  padding: 2px 2px 0;
}

.pw-branch {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  color: var(--pw-muted);
  font-size: 12px;
  font-weight: 700;
}

.pw-branch span::before { content: "●"; margin-right: 7px; color: #22c55e; font-size: 9px; }
.pw-branch strong { overflow: hidden; color: var(--pw-dark); text-overflow: ellipsis; white-space: nowrap; }

.pw-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 16px;
  padding: 20px;
  border: 1px solid #dbeafe;
  border-radius: 20px;
  background: linear-gradient(135deg, #eff6ff, #fff 56%, #eef2ff);
}

.pw-head p, .pw-section-title p { margin: 0; }
.pw-head > div > p { color: #2563eb; font-size: 10px; font-weight: 900; letter-spacing: .18em; text-transform: uppercase; }
.pw-head h2 { margin: 5px 0; font-size: 25px; line-height: 1.1; }
.pw-head span { color: var(--pw-muted); font-size: 13px; font-weight: 600; }

.pw-card {
  position: relative;
  margin-bottom: 12px;
  padding: 18px;
  overflow: visible;
  border: 1px solid var(--pw-border);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 6px 22px rgba(15, 23, 42, .045);
}

.pw-section-title {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  margin-bottom: 15px;
}

.pw-section-title i {
  display: flex;
  width: 31px;
  height: 31px;
  flex: 0 0 31px;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: #0f172a;
  color: #fff;
  font-style: normal;
  font-weight: 900;
}

.pw-section-title h3 { margin: 0 0 2px; font-size: 15px; }
.pw-section-title p { color: var(--pw-muted); font-size: 12px; font-weight: 600; line-height: 1.4; }
.pw-grid { display: grid; gap: 11px 13px; }
.pw-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.pw-shell label { display: block; min-width: 0; }

.pw-shell label > span, .pw-filters label > span {
  display: block;
  margin: 0 0 6px;
  color: #475569;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .075em;
  text-transform: uppercase;
}

.pw-shell input, .pw-shell select, .pw-shell textarea {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid #dbe3ee;
  border-radius: 11px;
  background: #fff;
  padding: 9px 11px;
  color: var(--pw-dark);
  font: 650 13px/1.25 inherit;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.pw-shell input:focus, .pw-shell select:focus, .pw-shell textarea:focus {
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .11);
}

.pw-shell input:disabled, .pw-shell select:disabled { cursor: not-allowed; background: #f8fafc; color: #64748b; }
.pw-shell textarea { min-height: 78px; resize: vertical; }
.pw-shell small { display: block; margin-top: 4px; color: #94a3b8; font-size: 10px; font-weight: 600; line-height: 1.35; }

.pw-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 11px;
  background: #2563eb;
  padding: 9px 15px;
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
  cursor: pointer;
  transition: filter .15s ease, transform .15s ease;
}

.pw-button:hover { filter: brightness(.97); transform: translateY(-1px); }
.pw-button:disabled { cursor: not-allowed; opacity: .55; transform: none; }
.pw-button-secondary { border: 1px solid var(--pw-border); background: #fff; color: #334155; }
.pw-button-primary { min-height: 46px; padding-inline: 20px; background: #0f172a; }
.pw-button-danger { background: #fee2e2; color: #b91c1c; }
.pw-button-small { min-height: 34px; padding: 6px 10px; font-size: 10px; }

.pw-product-picker {
  display: grid;
  grid-template-columns: minmax(300px, 2.2fr) minmax(110px, .55fr) minmax(190px, .9fr) auto;
  align-items: end;
  gap: 10px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid #e8edf5;
  border-radius: 15px;
  background: #f8fafc;
}

.pw-product-search { position: relative; min-width: 0; }
.pw-search-input { position: relative; }
.pw-search-input > span { position: absolute; top: 50%; left: 12px; z-index: 1; color: #64748b; font-size: 20px; transform: translateY(-52%); pointer-events: none; }
.pw-search-input input { padding-left: 38px; background: #fff; }

.pw-search-results {
  position: absolute;
  top: calc(100% + 7px);
  right: 0;
  left: 0;
  z-index: 120;
  max-height: 330px;
  overflow-y: auto;
  border: 1px solid #dbe3ee;
  border-radius: 14px;
  background: #fff;
  padding: 6px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, .18);
}

.pw-search-results[hidden] { display: none !important; }
.pw-search-result, .pw-create-product-link {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  padding: 10px;
  color: #334155;
  text-align: left;
  cursor: pointer;
}

.pw-search-result:hover, .pw-search-result.is-active { background: #eef2ff; }
.pw-search-result > span { min-width: 0; }
.pw-search-result > span:last-child { flex: none; text-align: right; }
.pw-search-result strong, .pw-search-result b { display: block; overflow: hidden; color: #0f172a; font-size: 12px; font-weight: 900; text-overflow: ellipsis; white-space: nowrap; }
.pw-search-result b { color: #4f46e5; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.pw-search-result small { margin-top: 2px; }
.pw-search-empty { padding: 13px 11px; color: #64748b; }
.pw-search-empty strong, .pw-search-empty span { display: block; font-size: 11px; }

.pw-create-product-link {
  justify-content: flex-start;
  margin-top: 4px;
  border-top: 1px solid #eef2f7;
  border-radius: 0 0 10px 10px;
  color: #1d4ed8;
}

.pw-create-product-link:hover { background: #eff6ff; }
.pw-create-product-link > span { display: grid; width: 31px; height: 31px; flex: none; place-items: center; border-radius: 9px; background: #dbeafe; font-size: 18px; }
.pw-create-product-link strong, .pw-create-product-link small { display: block; }
.pw-create-product-link strong { font-size: 12px; }
.pw-create-product-link small { color: #64748b; }
.pw-add-line { min-width: 105px; }

.pw-table-wrap { width: 100%; max-width: 100%; overflow-x: auto; border: 1px solid #edf1f6; border-radius: 12px; }
.pw-table { width: 100%; min-width: 680px; border-collapse: separate; border-spacing: 0; font-size: 12px; }
.pw-table th { padding: 10px; border-bottom: 1px solid var(--pw-border); background: #f8fafc; color: #64748b; text-align: left; font-size: 9px; letter-spacing: .08em; text-transform: uppercase; white-space: nowrap; }
.pw-table td { padding: 11px 10px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }
.pw-table tbody tr:last-child td { border-bottom: 0; }
.pw-table td > strong, .pw-table td > a > strong, .pw-link strong { display: block; }
.pw-table td > small, .pw-link small { display: block; margin-top: 3px; color: #94a3b8; }
.pw-empty { padding: 28px !important; color: #94a3b8; text-align: center; }
.pw-icon-button { width: 30px; height: 30px; border: 0; border-radius: 9px; background: #fee2e2; color: #b91c1c; font-size: 20px; cursor: pointer; }

.pw-totals { display: flex; justify-content: flex-end; gap: 22px; padding: 12px 7px 0; color: #64748b; font-size: 11px; }
.pw-totals span { min-width: 75px; }
.pw-totals strong { display: block; margin-top: 2px; color: #0f172a; font-size: 15px; }
.pw-readonly { min-height: 68px; border-radius: 13px; background: #f1f5f9; padding: 11px; }
.pw-readonly span, .pw-readonly small { display: block; color: #64748b; font-size: 10px; font-weight: 700; }
.pw-readonly strong { display: block; margin: 3px 0; font-size: 17px; }
.pw-notice, .pw-success { display: flex; align-items: flex-start; gap: 8px; border-radius: 14px; padding: 13px; }
.pw-notice { border: 1px solid #fde68a; background: #fffbeb; color: #92400e; }
.pw-notice strong, .pw-notice span { display: block; }
.pw-notice span { font-size: 12px; font-weight: 600; }
.pw-notes { margin-top: 13px; }

.pw-submit {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 4px;
  padding: 16px 18px;
  border: 1px solid #c7d2fe;
  border-radius: 17px;
  background: #eef2ff;
}

.pw-submit strong, .pw-submit span { display: block; }
.pw-submit span { margin-top: 3px; color: #475569; font-size: 12px; font-weight: 600; }
.pw-success { justify-content: space-between; margin-bottom: 12px; border: 1px solid #a7f3d0; background: #ecfdf5; color: #065f46; }
.pw-success strong, .pw-success span { display: block; }
.pw-success span { font-size: 12px; font-weight: 600; }
.pw-success button { border: 0; background: transparent; color: #047857; font-weight: 900; cursor: pointer; }

.pw-modal-backdrop { position: fixed; inset: 0; z-index: 2147483000; display: grid; place-items: center; overflow-y: auto; background: rgba(15, 23, 42, .58); padding: 16px; backdrop-filter: blur(4px); }
.pw-modal { width: min(680px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto; border-radius: 20px; background: #fff; box-shadow: 0 30px 80px rgba(15, 23, 42, .32); }
.pw-modal > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 20px 22px; border-bottom: 1px solid #e2e8f0; background: linear-gradient(135deg, #f8fafc, #eef2ff); }
.pw-modal > header span { color: #4f46e5; font-size: 9px; font-weight: 950; letter-spacing: .14em; text-transform: uppercase; }
.pw-modal > header h3 { margin: 4px 0 3px; font-size: 19px; }
.pw-modal > header p { margin: 0; color: #64748b; font-size: 11px; font-weight: 600; line-height: 1.45; }
.pw-modal-close { width: 34px; height: 34px; flex: none; border: 1px solid #dbe3ee; border-radius: 10px; background: #fff; color: #64748b; font-size: 21px; cursor: pointer; }
.pw-quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; padding: 20px 22px; }
.pw-span-2 { grid-column: span 2; }
.pw-modal footer { display: flex; justify-content: flex-end; gap: 9px; border-top: 1px solid #e2e8f0; background: #f8fafc; padding: 15px 22px; }

.pw-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.pw-metrics article { padding: 16px; border: 1px solid var(--pw-border); border-radius: 18px; background: #fff; }
.pw-metrics span { display: block; color: #64748b; font-size: 9px; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
.pw-metrics strong { display: block; margin-top: 6px; font-size: 20px; }
.pw-filters { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; align-items: end; gap: 10px; margin-bottom: 15px; }
.pw-link { border: 0; background: transparent; padding: 0; color: #0f172a; text-align: left; cursor: pointer; }
.pw-badge { display: inline-flex; border-radius: 999px; background: #f1f5f9; padding: 5px 8px; color: #475569; font-size: 9px; font-weight: 900; }
.pw-PAGADA { background: #dcfce7; color: #166534; }
.pw-PARCIAL, .pw-PENDIENTE { background: #fef3c7; color: #92400e; }
.pw-VENCIDA { background: #fee2e2; color: #b91c1c; }
.pw-NO_APLICA { background: #e2e8f0; color: #475569; }
.pw-detail-row > td { padding: 0 12px 14px !important; background: #f8fafc; }
.pw-detail { padding: 15px; border: 1px solid #dbeafe; border-radius: 16px; background: #fff; }
.pw-detail > div:first-child { display: flex; justify-content: space-between; margin-bottom: 10px; }
.pw-detail > div:first-child span { color: #64748b; font-size: 11px; font-weight: 600; }
.pw-detail-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.pw-loading, .pw-error { display: flex; min-height: 280px; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.pw-loading span { width: 32px; height: 32px; margin-bottom: 12px; border: 3px solid #dbeafe; border-top-color: #2563eb; border-radius: 50%; animation: pw-spin .8s linear infinite; }
.pw-error { padding: 30px; border: 1px solid #fecaca; border-radius: 22px; background: #fff; }
.pw-error p { color: #b91c1c; }
.pw-toast { position: fixed; right: 22px; bottom: 22px; z-index: 2147483647; max-width: 420px; border-radius: 14px; background: #0f172a; padding: 13px 16px; color: #fff; font-size: 12px; font-weight: 800; box-shadow: 0 16px 40px rgba(15, 23, 42, .28); }
.pw-toast-error { background: #b91c1c; }


/* Importación inteligente de DTE de proveedores */
.pw-toolbar-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }

.pw-dte-prepared {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
  border: 1px solid #bfdbfe;
  border-radius: 15px;
  background: linear-gradient(135deg, #eff6ff, #f8fafc);
  padding: 13px 15px;
}
.pw-dte-prepared strong, .pw-dte-prepared span { display: block; }
.pw-dte-prepared strong { flex: none; color: #1d4ed8; font-size: 12px; }
.pw-dte-prepared span { color: #475569; font-size: 11px; font-weight: 650; line-height: 1.45; }

.pw-dte-modal { width: min(1120px, 100%); }
.pw-dte-body { padding: 20px 22px; }
.pw-dte-search-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1.25fr) minmax(180px, .75fr) auto;
  align-items: end;
  gap: 11px;
}
.pw-dte-divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: #94a3b8; font-size: 10px; font-weight: 900; text-transform: uppercase; }
.pw-dte-divider::before, .pw-dte-divider::after { content: ""; height: 1px; flex: 1; background: #e2e8f0; }
.pw-dte-divider span { flex: none; }
.pw-dte-upload {
  position: relative;
  display: grid !important;
  min-height: 92px;
  place-items: center;
  border: 1px dashed #93c5fd;
  border-radius: 16px;
  background: #f8fbff;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease, transform .15s ease;
}
.pw-dte-upload:hover { border-color: #2563eb; background: #eff6ff; transform: translateY(-1px); }
.pw-dte-upload strong { display: block; color: #0f172a; font-size: 13px; }
.pw-dte-upload > span { display: block !important; margin: 5px 0 0 !important; color: #64748b !important; font-size: 11px !important; font-weight: 650 !important; }
.pw-dte-upload input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.pw-dte-empty {
  display: grid;
  min-height: 170px;
  place-items: center;
  align-content: center;
  margin-top: 18px;
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  background: #f8fafc;
  padding: 24px;
  text-align: center;
}
.pw-dte-empty::before { content: "↥"; display: grid; width: 42px; height: 42px; margin-bottom: 9px; place-items: center; border-radius: 13px; background: #e0e7ff; color: #4338ca; font-size: 23px; font-weight: 900; }
.pw-dte-empty strong, .pw-dte-empty span { display: block; }
.pw-dte-empty strong { font-size: 13px; }
.pw-dte-empty span { max-width: 590px; margin-top: 5px; color: #64748b; font-size: 11px; font-weight: 600; line-height: 1.5; }

.pw-dte-result { margin-top: 18px; }
.pw-dte-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.pw-dte-summary > div { min-width: 0; border: 1px solid #e2e8f0; border-radius: 14px; background: #fff; padding: 12px; }
.pw-dte-summary span, .pw-dte-summary strong, .pw-dte-summary small { display: block; }
.pw-dte-summary span { color: #64748b; font-size: 9px; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.pw-dte-summary strong { overflow: hidden; margin-top: 4px; color: #0f172a; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.pw-dte-summary small { margin-top: 3px; color: #94a3b8; font-size: 10px; font-weight: 650; }

.pw-dte-alert { display: flex; align-items: flex-start; gap: 9px; margin: 10px 0; border: 1px solid #fde68a; border-radius: 13px; background: #fffbeb; padding: 11px 13px; color: #92400e; }
.pw-dte-alert::before { content: "!"; display: grid; width: 23px; height: 23px; flex: 0 0 23px; place-items: center; border-radius: 8px; background: rgba(146, 64, 14, .1); font-size: 12px; font-weight: 950; }
.pw-dte-alert strong, .pw-dte-alert span { display: block; }
.pw-dte-alert strong { font-size: 11px; }
.pw-dte-alert span { margin-top: 2px; font-size: 10px; font-weight: 650; line-height: 1.45; }
.pw-dte-alert-danger { border-color: #fecaca; background: #fef2f2; color: #991b1b; }
.pw-dte-alert-danger::before { background: rgba(153, 27, 27, .09); }
.pw-dte-alert-ok { border-color: #a7f3d0; background: #ecfdf5; color: #065f46; }
.pw-dte-alert-ok::before { content: "✓"; background: rgba(6, 95, 70, .09); }

.pw-dte-table-wrap { margin-top: 12px; }
.pw-dte-table { min-width: 850px; }
.pw-dte-table td:first-child { min-width: 250px; }
.pw-dte-table td:last-child { min-width: 310px; }
.pw-dte-table td:last-child select + select, .pw-dte-table td:last-child select + small { margin-top: 6px; }
.pw-dte-number { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.pw-dte-lock { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 13px; border: 1px solid #c7d2fe; border-radius: 14px; background: #eef2ff; padding: 12px 14px; }
.pw-dte-lock::before { content: "✓"; display: grid; width: 24px; height: 24px; flex: 0 0 24px; place-items: center; border-radius: 8px; background: #4f46e5; color: #fff; font-size: 11px; font-weight: 950; }
.pw-dte-lock strong, .pw-dte-lock span { display: block; }
.pw-dte-lock strong { color: #312e81; font-size: 11px; }
.pw-dte-lock span { margin-top: 2px; color: #475569; font-size: 10px; font-weight: 650; line-height: 1.45; }

.pw-dte-invoice-detail { margin-top: 13px; border: 1px solid #e2e8f0; border-radius: 14px; background: #f8fafc; padding: 12px; }
.pw-dte-invoice-detail-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 10px; }
.pw-dte-invoice-detail-head strong, .pw-dte-invoice-detail-head span { display: block; }
.pw-dte-invoice-detail-head strong { font-size: 11px; }
.pw-dte-invoice-detail-head span { margin-top: 2px; color: #64748b; font-size: 10px; font-weight: 650; line-height: 1.45; }
.pw-dte-stock-badge { background: #dcfce7; color: #166534; }
.pw-dte-no-stock-badge { background: #e2e8f0; color: #475569; }

@keyframes pw-spin { to { transform: rotate(360deg); } }

@media (max-width: 1180px) {
  .pw-grid-4 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pw-product-picker { grid-template-columns: minmax(280px, 2fr) minmax(100px, .55fr) minmax(180px, 1fr); }
  .pw-product-picker .pw-add-line { grid-column: 3; width: 100%; }
  .pw-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pw-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .pw-grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pw-dte-search-grid, .pw-dte-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pw-dte-search-grid .pw-button { width: 100%; }
  .pw-product-picker { grid-template-columns: minmax(0, 1.7fr) minmax(100px, .6fr); }
  .pw-product-picker > label:nth-of-type(2) { grid-column: 1; }
  .pw-product-picker .pw-add-line { grid-column: 2; width: 100%; }
}

@media (max-width: 620px) {
  .pw-toolbar { align-items: stretch; flex-direction: column; }
  .pw-toolbar-actions { display: grid; grid-template-columns: 1fr; }
  .pw-toolbar .pw-button { width: 100%; }
  .pw-dte-prepared, .pw-dte-invoice-detail-head { align-items: stretch; flex-direction: column; }
  .pw-dte-search-grid, .pw-dte-summary { grid-template-columns: 1fr; }
  .pw-dte-body { padding: 16px; }
  .pw-card { padding: 14px; border-radius: 15px; }
  .pw-grid-4, .pw-product-picker, .pw-metrics, .pw-filters, .pw-quick-grid { grid-template-columns: 1fr; }
  .pw-product-picker .pw-add-line, .pw-product-picker > label:nth-of-type(2), .pw-span-2 { grid-column: auto; }
  .pw-product-picker .pw-add-line { width: 100%; }
  .pw-submit, .pw-success { align-items: stretch; flex-direction: column; }
  .pw-submit .pw-button { width: 100%; }
  .pw-totals { justify-content: space-between; gap: 8px; }
  .pw-totals span { min-width: 0; }
  .pw-totals strong { font-size: 13px; }
  .pw-modal-backdrop { padding: 8px; }
  .pw-modal { max-height: calc(100dvh - 16px); border-radius: 15px; }
  .pw-modal > header, .pw-quick-grid { padding: 16px; }
  .pw-modal footer { display: grid; grid-template-columns: 1fr; padding: 13px 16px; }
  .pw-toast { right: 10px; bottom: 10px; left: 10px; max-width: none; }
}
