/* =====================================================================
   DedicaQR — Sprint 21 CSS
   Notas de Crédito y Débito: badges tipo (NC roja / ND verde), timeline
   horizontal 4 pasos, items editor con grid, invoice search results,
   totales horizontales, stats matrix 2-card.
   Aditivo sobre Sprints 1-20.
   ===================================================================== */

:root {
  --nc-color:        #dc2626;
  --nc-bg:           #fee2e2;
  --nc-border:       #fca5a5;
  --nd-color:        #059669;
  --nd-bg:           #d1fae5;
  --nd-border:       #6ee7b7;

  --ncn-pending:     #d97706;
  --ncn-pending-bg:  #fef3c7;
  --ncn-sent:        #1d4ed8;
  --ncn-sent-bg:     #dbeafe;
  --ncn-approved:    #059669;
  --ncn-approved-bg: #d1fae5;
  --ncn-rejected:    #dc2626;
  --ncn-rejected-bg: #fee2e2;
  --ncn-cancelled:   #6b7280;
  --ncn-cancelled-bg:#f3f4f6;
}

/* =====================================================================
   TIPO BADGES (NC / ND)
   ===================================================================== */

.ncn-tipo-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.6px;
  vertical-align: middle;
  min-width: 32px;
  text-align: center;
}
.ncn-tipo-credit { background: var(--nc-bg); color: var(--nc-color); border: 1px solid var(--nc-border); }
.ncn-tipo-debit  { background: var(--nd-bg); color: var(--nd-color); border: 1px solid var(--nd-border); }

/* =====================================================================
   STATUS BADGES
   ===================================================================== */

.ncn-status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  vertical-align: middle;
}
.ncn-status-pending   { background: var(--ncn-pending-bg);   color: var(--ncn-pending); }
.ncn-status-sent      { background: var(--ncn-sent-bg);      color: var(--ncn-sent); }
.ncn-status-approved  { background: var(--ncn-approved-bg);  color: var(--ncn-approved); }
.ncn-status-rejected  { background: var(--ncn-rejected-bg);  color: var(--ncn-rejected); }
.ncn-status-cancelled { background: var(--ncn-cancelled-bg); color: var(--ncn-cancelled); }

/* =====================================================================
   STATS MATRIX (index)
   ===================================================================== */

.ncn-stats-matrix {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  margin: 14px 0 22px;
}
.ncn-stats-card {
  background: white;
  border-radius: 10px;
  padding: 16px 18px;
  border-left: 4px solid #e5e7eb;
}
.ncn-stats-card h3 { margin: 0 0 12px; font-size: 15px; }
.ncn-stats--credit { border-left-color: var(--nc-color); }
.ncn-stats--debit  { border-left-color: var(--nd-color); }
.ncn-stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.ncn-stat { text-align: center; }
.ncn-stat-label {
  display: block;
  font-size: 11px;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.ncn-stat-value {
  display: block;
  font-size: 1.5rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
  margin-top: 2px;
}

/* =====================================================================
   TABLA LIST
   ===================================================================== */

.ncn-table td { vertical-align: top; font-size: 13px; }

/* =====================================================================
   INVOICE SEARCH (new form)
   ===================================================================== */

.ncn-invoice-search {
  background: var(--dqr-bg, #FFF8F5);
  border-radius: 10px;
  padding: 16px 18px;
  margin: 10px 0;
}
.ncn-invoice-search input[type=text] {
  width: 100%;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid #ddd;
  border-radius: 6px;
}
.ncn-invoice-results {
  margin-top: 10px;
  max-height: 320px;
  overflow-y: auto;
}
.ncn-inv-result {
  padding: 10px 12px;
  border: 1px solid #ececec;
  border-radius: 6px;
  margin-bottom: 6px;
  background: white;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-size: 13px;
}
.ncn-inv-result:hover {
  border-color: var(--dqr-brand, #C9184A);
  background: #fffaf6;
}
.ncn-no-results {
  text-align: center;
  color: #888;
  font-style: italic;
  padding: 20px;
}
.ncn-tag-tiny {
  display: inline-block;
  padding: 1px 6px;
  background: var(--ncn-pending-bg);
  color: var(--ncn-pending);
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  margin-left: 4px;
}

.ncn-invoice-selected {
  margin: 10px 0;
}
.ncn-inv-card {
  background: white;
  border: 1px solid #ececec;
  border-radius: 10px;
  padding: 16px 18px;
}
.ncn-inv-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #f0f0f0;
}

/* =====================================================================
   ITEMS EDITOR (new form)
   ===================================================================== */

.ncn-items-editor {
  margin: 10px 0;
}
.ncn-item-row {
  display: grid;
  grid-template-columns: 100px 1fr 80px 110px 60px 90px 32px;
  gap: 6px;
  margin-bottom: 6px;
  align-items: center;
}
.ncn-item-row input {
  padding: 6px 8px;
  font-size: 13px;
  border: 1px solid #ddd;
  border-radius: 4px;
}
.ncn-item-row .ncn-item-cant,
.ncn-item-row .ncn-item-precio,
.ncn-item-row .ncn-item-unidad {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.ncn-item-subtotal {
  text-align: right;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--dqr-brand, #C9184A);
  padding: 0 6px;
}
.ncn-item-rm {
  padding: 4px 8px;
  font-size: 16px;
  line-height: 1;
}

/* =====================================================================
   TIMELINE (show)
   ===================================================================== */

.ncn-timeline {
  display: flex;
  gap: 0;
  margin: 18px 0 22px;
  background: white;
  border: 1px solid #ececec;
  border-radius: 12px;
  padding: 18px;
  overflow-x: auto;
}
.ncn-tl-step {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  min-width: 150px;
  opacity: 0.4;
  position: relative;
  transition: opacity 0.2s;
}
.ncn-tl-step:not(:last-child)::after {
  content: '';
  position: absolute;
  right: -1px;
  top: 50%;
  width: 1px;
  height: 60%;
  background: #e5e7eb;
  transform: translateY(-50%);
}
.ncn-tl-step.ncn-tl-done { opacity: 1; }
.ncn-tl-step.ncn-tl-done .ncn-tl-icon {
  background: var(--ncn-approved);
  color: white;
}
.ncn-tl-step.ncn-tl-failed { opacity: 1; }
.ncn-tl-step.ncn-tl-failed .ncn-tl-icon {
  background: var(--ncn-rejected);
  color: white;
}
.ncn-tl-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #e5e7eb;
  color: #6b7280;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

/* =====================================================================
   ACTIONS ROW (show)
   ===================================================================== */

.ncn-actions-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 14px 0 22px;
}

/* =====================================================================
   XML VIEWER
   ===================================================================== */

.ncn-xml-viewer summary {
  cursor: pointer;
  font-weight: 600;
  padding: 8px 12px;
  background: #fafafa;
  border-radius: 6px;
  border: 1px solid #ececec;
}
.ncn-xml-code {
  background: #1e293b;
  color: #e2e8f0;
  padding: 14px;
  border-radius: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.5;
  max-height: 500px;
  overflow: auto;
  margin-top: 8px;
  white-space: pre-wrap;
  word-break: break-all;
}

/* =====================================================================
   INVOICE BLOCK (partial _notes_block.php)
   ===================================================================== */

.ncn-invoice-block {
  margin-top: 24px;
  padding: 16px;
  background: var(--dqr-bg, #FFF8F5);
  border-radius: 10px;
  border-left: 4px solid var(--dqr-brand, #C9184A);
}
.ncn-invoice-block-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.ncn-invoice-block-head h3 { margin: 0; font-size: 16px; }
.ncn-invoice-block-head h3 small { color: #888; font-weight: 400; }

.ncn-invoice-totals {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 24px;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid rgba(0,0,0,0.05);
  margin-bottom: 10px;
}
.ncn-tot { display: flex; flex-direction: column; }
.ncn-tot-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #888;
}
.ncn-tot-value {
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.ncn-tot-effective .ncn-tot-value {
  color: var(--dqr-brand, #C9184A);
  font-size: 1.4rem;
}

/* =====================================================================
   RESPONSIVE
   ===================================================================== */

@media (max-width: 1024px) {
  .ncn-stats-matrix { grid-template-columns: 1fr; }
  .ncn-timeline { flex-wrap: wrap; }
  .ncn-tl-step { flex: 1 1 calc(50% - 12px); min-width: 130px; }
  .ncn-tl-step::after { display: none; }
}

@media (max-width: 768px) {
  .ncn-stats-row { grid-template-columns: repeat(2, 1fr); gap: 12px 8px; }
  .ncn-item-row {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .ncn-item-row > * { grid-column: span 2; }
  .ncn-item-row .ncn-item-cant,
  .ncn-item-row .ncn-item-precio { grid-column: span 1; }
  .ncn-item-subtotal { grid-column: span 2; text-align: left; }
  .ncn-tl-step { flex: 1 1 100%; }
  .ncn-invoice-totals { gap: 10px 16px; }
  .ncn-tot-effective .ncn-tot-value { font-size: 1.2rem; }
}

@media (max-width: 480px) {
  .ncn-stats-row { grid-template-columns: 1fr 1fr; }
  .ncn-stat-value { font-size: 1.2rem; }
  .ncn-actions-row > form,
  .ncn-actions-row > * { width: 100%; }
}
