/* Orden de compra — modal estilo ERP (solo presentación) */
#po-detail-modal {
  --po-erp-primary: #2563eb;
  --po-erp-success: #22c55e;
  --po-erp-warn: #f59e0b;
  --po-erp-danger: #ef4444;
  --po-erp-text: #0f172a;
  --po-erp-muted: #64748b;
  --po-erp-border: #e2e8f0;
  --po-erp-bg: #f8fafc;
  --po-erp-card: #ffffff;
  --po-erp-radius: 14px;
  --po-erp-gap: 1rem;
  font-family: Inter, system-ui, sans-serif;
}

#po-detail-modal .po-erp-dialog {
  width: 90vw;
  max-width: 1700px;
  margin: calc((100vh - 92vh) / 2) auto;
  margin: calc((100dvh - 92dvh) / 2) auto;
  max-height: 92vh;
  max-height: 92dvh;
}

#po-detail-modal .po-erp-dialog .modal-content {
  max-height: 92vh;
  max-height: 92dvh;
  border: none;
  border-radius: 16px;
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.18);
  background: var(--po-erp-bg);
  overflow: hidden;
}

#po-detail-modal .po-erp__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.75rem;
  background: var(--po-erp-card);
  border-bottom: 1px solid var(--po-erp-border);
}

#po-detail-modal .po-erp__header-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1.25rem;
  min-width: 0;
  flex: 1;
}

#po-detail-modal #po-form-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--po-erp-text);
  letter-spacing: -0.02em;
}

#po-detail-modal .po-erp__chip {
  display: inline-flex;
  align-items: center;
  max-width: 280px;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#po-detail-modal .po-erp__badge {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: #f1f5f9;
  color: var(--po-erp-muted);
}

#po-detail-modal .po-erp__badge[data-status="pending"] {
  background: #fef3c7;
  color: #b45309;
}

#po-detail-modal .po-erp__badge[data-status="sent"] {
  background: #dbeafe;
  color: #1d4ed8;
}

#po-detail-modal .po-erp__badge[data-status="received"] {
  background: #dcfce7;
  color: #15803d;
}

#po-detail-modal .po-erp__body {
  padding: 1.5rem 1.75rem;
  background: var(--po-erp-bg);
  overflow: auto;
}

#po-detail-modal #po-form.crm-form {
  display: flex;
  flex-direction: column;
  gap: var(--po-erp-gap);
  max-width: none;
}

#po-detail-modal #po-form.crm-form > label,
#po-detail-modal #po-form.crm-form > .main-lead {
  /* labels sueltos se envuelven en cards */
}

#po-detail-modal .po-erp-card {
  background: var(--po-erp-card);
  border: 1px solid var(--po-erp-border);
  border-radius: var(--po-erp-radius);
  padding: 1.35rem 1.5rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  transition: box-shadow 150ms ease, border-color 150ms ease;
  height: auto;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

#po-detail-modal .po-erp-card:hover {
  border-color: #cbd5e1;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
}

#po-detail-modal .po-erp-card__title {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--po-erp-text);
}

#po-detail-modal .po-erp-card__lead {
  margin: 0 0 1rem;
  font-size: 0.875rem;
  color: var(--po-erp-muted);
  line-height: 1.45;
}

/* Una sola columna vertical: lectura de arriba hacia abajo */
#po-detail-modal .po-erp-grid,
#po-detail-modal .po-erp-create,
#po-detail-modal #po-form > .crm-form-grid,
#po-detail-modal .crm-form-grid {
  display: flex !important;
  flex-direction: column !important;
  gap: var(--po-erp-gap) !important;
  grid-template-columns: none !important;
  width: 100%;
  max-width: 100%;
}

#po-detail-modal .po-erp-col,
#po-detail-modal .crm-form-grid > *,
#po-detail-modal .po-erp-grid > * {
  display: flex;
  flex-direction: column;
  gap: var(--po-erp-gap);
  min-width: 0;
  width: 100% !important;
  max-width: 100% !important;
  grid-column: auto !important;
}

#po-detail-modal .po-erp-row-meta {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

#po-detail-modal #po-source-context.po-source-context {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
}

#po-detail-modal #po-source-context.hidden {
  display: none !important;
}

#po-detail-modal #po-source-context dl {
  display: contents;
}

#po-detail-modal #po-source-context dt {
  display: none;
}

#po-detail-modal #po-source-context dd {
  margin: 0;
  padding: 0.85rem 1rem;
  background: var(--po-erp-card);
  border: 1px solid var(--po-erp-border);
  border-radius: 12px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--po-erp-text);
}

#po-detail-modal #po-source-context dd::before {
  content: attr(data-label);
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--po-erp-muted);
}

#po-detail-modal #po-source-context > .main-lead {
  display: none;
}

/* Create / quote block */

#po-detail-modal .po-erp-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.85rem;
}

#po-detail-modal .po-erp-field > label,
#po-detail-modal .po-erp-card label {
  font-size: 0.84rem;
  font-weight: 600;
  color: #475569;
  margin: 0;
}

#po-detail-modal .po-erp-field .main-lead,
#po-detail-modal .po-erp-card > .main-lead {
  font-size: 0.82rem;
  color: var(--po-erp-muted);
  margin: 0 0 0.35rem;
}

#po-detail-modal #po-form select,
#po-detail-modal #po-form input[type="text"],
#po-detail-modal #po-form input[type="number"],
#po-detail-modal #po-form input[type="date"],
#po-detail-modal #po-form input:not([type="file"]):not([type="hidden"]):not([type="checkbox"]):not([type="radio"]) {
  min-height: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--po-erp-border);
  padding: 0.5rem 0.85rem;
  font-size: 0.9375rem;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

#po-detail-modal #po-form select:hover,
#po-detail-modal #po-form input:hover {
  border-color: #cbd5e1;
}

#po-detail-modal #po-form select:focus,
#po-detail-modal #po-form input:focus {
  outline: none;
  border-color: var(--po-erp-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

#po-detail-modal .po-quote-lookup-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
}

/* Products table (readonly summary) */
#po-detail-modal #po-readonly-summary.po-readonly-summary {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}

#po-detail-modal #po-readonly-summary.hidden {
  display: none !important;
}

#po-detail-modal .po-erp-table-wrap {
  max-height: min(42vh, 420px);
  overflow: auto;
  border: 1px solid var(--po-erp-border);
  border-radius: 12px;
}

#po-detail-modal .po-erp-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.875rem;
}

#po-detail-modal .po-erp-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #f1f5f9;
  color: #475569;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.7rem 0.85rem;
  border-bottom: 1px solid var(--po-erp-border);
  white-space: nowrap;
}

#po-detail-modal .po-erp-table tbody td {
  padding: 0.85rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
  color: var(--po-erp-text);
}

#po-detail-modal .po-erp-table tbody tr {
  transition: background 150ms ease;
}

#po-detail-modal .po-erp-table tbody tr:hover {
  background: #f8fafc;
}

#po-detail-modal .po-erp-table .po-erp-prod {
  min-width: 220px;
  max-width: 420px;
  font-weight: 600;
  line-height: 1.35;
  white-space: normal;
  word-break: break-word;
}

#po-detail-modal .po-erp-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#po-detail-modal .po-erp-table .po-erp-serial-cell {
  font-size: 0.8rem;
  color: var(--po-erp-muted);
}

#po-detail-modal .po-erp-table .po-erp-serial-cell.is-missing {
  color: #b45309;
  font-weight: 600;
}

/* Lines create table */
#po-detail-modal #po-lines-wrap {
  overflow: auto;
  border: 1px solid var(--po-erp-border);
  border-radius: 12px;
  width: 100%;
}

#po-detail-modal #po-lines-wrap table {
  width: 100%;
  min-width: 100%;
}

#po-detail-modal #po-lines-wrap .po-lines-table,
#po-detail-modal #po-lines-wrap table.users-table {
  table-layout: auto;
}

/* Summary sidebar */
#po-detail-modal .po-erp-summary {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#po-detail-modal .po-erp-total-label {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--po-erp-muted);
}

#po-detail-modal #po-panel-total-pay,
#po-detail-modal .po-erp-total-value {
  margin: 0.2rem 0 0;
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--po-erp-text);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

#po-detail-modal .po-erp-summary-meta {
  display: grid;
  gap: 0.65rem;
  margin-top: 0.25rem;
}

#po-detail-modal .po-erp-summary-meta__row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  font-size: 0.875rem;
}

#po-detail-modal .po-erp-summary-meta__row span {
  color: var(--po-erp-muted);
}

#po-detail-modal .po-erp-summary-meta__row strong {
  color: var(--po-erp-text);
  font-weight: 600;
  text-align: right;
}

#po-detail-modal #po-edit-payment-panel {
  display: block;
  width: 100%;
}

#po-detail-modal #po-edit-payment-panel.hidden {
  display: none !important;
}

#po-detail-modal .po-erp-create-fields.hidden {
  display: none !important;
}

#po-detail-modal .po-pay-summary-card {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}

#po-detail-modal .po-pay-summary-card__row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1rem;
}

#po-detail-modal .po-pay-summary-card__label {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--po-erp-muted);
}

#po-detail-modal .po-pay-summary-card__total {
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--po-erp-text);
}

#po-detail-modal .po-pay-summary-card__actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  justify-content: flex-start;
}

#po-detail-modal .po-pay-summary-card > .main-lead {
  font-size: 0.8rem;
  color: var(--po-erp-muted);
}

#po-detail-modal #po-credit-notice.msg {
  margin: 0 0 0.75rem;
  border-radius: 10px;
}

/* Reception serials */
#po-detail-modal #po-item-serials-panel {
  margin: 0 !important;
}

#po-detail-modal #po-item-serials-panel.hidden {
  display: none !important;
}

#po-detail-modal #po-item-serials-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#po-detail-modal .po-serial-line {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 0.75rem 1rem;
  align-items: end;
  padding: 0.95rem 1rem;
  border: 1px solid var(--po-erp-border);
  border-radius: 12px;
  background: #f8fafc;
  transition: border-color 150ms ease, background 150ms ease;
}

#po-detail-modal .po-serial-line:hover {
  border-color: #bfdbfe;
  background: #fff;
}

#po-detail-modal .po-serial-label {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--po-erp-text);
}

#po-detail-modal .po-serial-hint {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--po-erp-muted);
}

#po-detail-modal .po-serial-line .po-order-item-serial {
  grid-column: 1 / -1;
  width: 100%;
}

#po-detail-modal .po-serial-line.is-erp {
  grid-template-columns: 1fr;
}

#po-detail-modal .po-serial-line.is-erp .po-serial-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.35rem 1rem;
}

#po-detail-modal .po-serial-qty {
  font-size: 0.8rem;
  font-weight: 600;
  color: #1d4ed8;
  background: #eff6ff;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}

/* Status timeline */
#po-detail-modal .po-erp-timeline {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}

#po-detail-modal .po-erp-timeline li {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.84rem;
  color: var(--po-erp-muted);
  font-weight: 500;
}

#po-detail-modal .po-erp-timeline li::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #cbd5e1;
  flex-shrink: 0;
  transition: background 150ms ease, box-shadow 150ms ease;
}

#po-detail-modal .po-erp-status-card:has(#po-status option[value="pending"]:checked) .po-erp-timeline li[data-step="pending"],
#po-detail-modal .po-erp-status-card:has(#po-status option[value="sent"]:checked) .po-erp-timeline li[data-step="pending"],
#po-detail-modal .po-erp-status-card:has(#po-status option[value="sent"]:checked) .po-erp-timeline li[data-step="sent"],
#po-detail-modal .po-erp-status-card:has(#po-status option[value="received"]:checked) .po-erp-timeline li[data-step="pending"],
#po-detail-modal .po-erp-status-card:has(#po-status option[value="received"]:checked) .po-erp-timeline li[data-step="sent"],
#po-detail-modal .po-erp-status-card:has(#po-status option[value="received"]:checked) .po-erp-timeline li[data-step="received"] {
  color: var(--po-erp-text);
  font-weight: 600;
}

#po-detail-modal .po-erp-status-card:has(#po-status option[value="pending"]:checked) .po-erp-timeline li[data-step="pending"]::before,
#po-detail-modal .po-erp-status-card:has(#po-status option[value="sent"]:checked) .po-erp-timeline li[data-step="pending"]::before,
#po-detail-modal .po-erp-status-card:has(#po-status option[value="sent"]:checked) .po-erp-timeline li[data-step="sent"]::before,
#po-detail-modal .po-erp-status-card:has(#po-status option[value="received"]:checked) .po-erp-timeline li[data-step="pending"]::before,
#po-detail-modal .po-erp-status-card:has(#po-status option[value="received"]:checked) .po-erp-timeline li[data-step="sent"]::before,
#po-detail-modal .po-erp-status-card:has(#po-status option[value="received"]:checked) .po-erp-timeline li[data-step="received"]::before {
  background: var(--po-erp-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

#po-detail-modal .po-erp-status-card:has(#po-status option[value="received"]:checked) .po-erp-timeline li[data-step="paid"] {
  color: var(--po-erp-text);
}

/* Buttons */
#po-detail-modal .po-erp-btn,
#po-detail-modal #btn-po-save,
#po-detail-modal #btn-po-new,
#po-detail-modal #btn-po-save-serials,
#po-detail-modal #btn-po-open-pay-modal,
#po-detail-modal #btn-po-add-line,
#po-detail-modal #btn-po-quote-lookup,
#po-detail-modal #btn-po-sign-clear,
#po-detail-modal #btn-po-sign-order {
  min-height: 42px;
  height: 42px;
  padding: 0 1.1rem !important;
  border-radius: 10px !important;
  font-size: 0.875rem !important;
  font-weight: 600;
  width: auto !important;
  max-width: none;
  display: inline-flex !important;
  align-items: center;
  gap: 0.4rem;
  transition: transform 150ms ease, background 150ms ease, box-shadow 150ms ease;
}

#po-detail-modal #btn-po-open-pay-modal {
  background: var(--po-erp-primary) !important;
}

#po-detail-modal #btn-po-save:hover,
#po-detail-modal #btn-po-open-pay-modal:hover,
#po-detail-modal #btn-po-save-serials:hover {
  transform: translateY(-1px);
}

#po-detail-modal .po-erp-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0.55rem;
  margin-top: 0.25rem;
  padding-top: 0.25rem;
}

#po-detail-modal .po-erp-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.55rem;
  margin-top: 0.25rem;
  padding: 1rem 0 0;
  border-top: 1px solid var(--po-erp-border);
}

#po-detail-modal #po-sign-panel {
  margin: 0;
}

#po-detail-modal #po-sign-panel.hidden {
  display: none !important;
}

#po-detail-modal #po-form-msg {
  margin-top: 0.5rem;
}

#po-detail-modal #po-create-block.hidden {
  display: none !important;
}

#po-detail-modal .hr-fieldset {
  border: 1px solid var(--po-erp-border);
  border-radius: 12px;
  padding: 1rem;
  margin: 0 0 1rem;
  background: #f8fafc;
}

#po-detail-modal .hr-fieldset legend {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--po-erp-text);
  padding: 0 0.35rem;
}

#po-detail-modal #po-source-context.po-source-context {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

#po-detail-modal .po-serial-line {
  grid-template-columns: 1fr;
}

@media (max-width: 900px) {
  #po-detail-modal .po-erp__body {
    padding: 1rem;
  }

  #po-detail-modal .po-erp__header {
    padding: 0.9rem 1rem;
  }

  #po-detail-modal #po-panel-total-pay,
  #po-detail-modal .po-pay-summary-card__total {
    font-size: 1.75rem;
  }
}
