/* FastEntryPurchase — Excel / Tabular Matrix View Styles */

#fep-table-modal-container {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: #1e293b;
}

/* Modal Overlay & Window — Full Screen below Dolibarr main top bar */
.fep-table-overlay {
  position: fixed;
  top: var(--fep-top-offset, 50px);
  left: 0;
  right: 0;
  bottom: 0;
  width: 100vw;
  height: calc(100vh - var(--fep-top-offset, 50px));
  z-index: 990;
  background-color: rgba(15, 23, 42, 0.35);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: stretch;
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

.fep-table-window {
  position: relative;
  background: #ffffff;
  border-radius: 0;
  box-shadow: none;
  width: 100vw;
  max-width: 100vw;
  height: 100%;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: none;
  border-top: 1px solid #cbd5e1;
}

/* Header bar */
.fep-table-header {
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  padding: 10px 18px;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.fep-provider-badge {
  display: inline-flex;
  align-items: center;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.fep-btn-change-supplier {
  margin-left: 8px;
  background: #ffffff;
  border: 1px solid #93c5fd;
  color: #1d4ed8;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
.fep-btn-change-supplier:hover {
  background: #2563eb;
  color: #ffffff;
  border-color: #1d4ed8;
}

/* Modal Selector de Proveedor */
.fep-supplier-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.fep-supplier-modal-window {
  background: #ffffff;
  border-radius: 12px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #cbd5e1;
  animation: fep-slidein 0.25s ease;
}
.fep-supplier-modal-header {
  padding: 12px 18px;
  background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.fep-supplier-modal-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.fep-supplier-search-input {
  width: 100%;
  border: 1.5px solid #cbd5e1;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  color: #1e293b;
  outline: none;
  box-sizing: border-box;
}
.fep-supplier-search-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}
.fep-supplier-list {
  max-height: 250px;
  overflow-y: auto;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
}
.fep-supplier-item {
  padding: 9px 12px;
  border-bottom: 1px solid #edf2f7;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #ffffff;
  transition: background-color 0.15s ease;
  font-size: 12.5px;
}
.fep-supplier-item:last-child {
  border-bottom: none;
}
.fep-supplier-item:hover {
  background-color: #eff6ff;
}
.fep-supplier-item.selected {
  background-color: #dbeafe;
  font-weight: 700;
}
.fep-supplier-badge-active {
  background: #2563eb;
  color: #ffffff;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 700;
}
.fep-supplier-modal-footer {
  padding: 12px 18px;
  background: #f8fafc;
  border-top: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.fep-date-range-box {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  padding: 4px 12px;
  border-radius: 8px;
  font-size: 12px;
  color: #475569;
}

.fep-date-input {
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 12px;
  background: #ffffff;
  color: #334155;
  outline: none;
}
.fep-date-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

/* Toolbar search / scan bar */
.fep-table-toolbar {
  padding: 8px 18px;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

#fep-t-search-results {
  max-height: 260px;
  overflow-y: auto !important;
  overscroll-behavior: contain;
  background: #ffffff;
  z-index: 999;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

/* Table scroll area */
.fep-table-scroll-wrap {
  flex: 1;
  overflow: auto;
  position: relative;
  background: #ffffff;
}

/* Matrix Table Layout */
.fep-grid-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  line-height: 1.35;
}

.fep-grid-table thead th {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #f1f5f9;
  color: #334155;
  font-weight: 700;
  padding: 8px 6px;
  text-align: center;
  border-bottom: 2px solid #cbd5e1;
  border-right: 1px solid #e2e8f0;
  white-space: normal;
  vertical-align: middle;
  font-size: 12px;
}

.fep-grid-table tbody td {
  padding: 4px 5px;
  border-bottom: 1px solid #e2e8f0;
  border-right: 1px solid #f1f5f9;
  vertical-align: middle;
  background: #ffffff;
  font-size: 13px;
}

.fep-grid-table tbody tr:hover td {
  background-color: #f8fafc;
}

/* Sticky columns */
.fep-sticky-col-0 {
  position: sticky;
  left: 0;
  z-index: 10;
  width: 40px;
  min-width: 40px;
  max-width: 40px;
  background-color: #f8fafc !important;
  text-align: center;
  border-right: 1px solid #e2e8f0;
}
.fep-grid-table thead th.fep-sticky-col-0 {
  z-index: 30;
  background-color: #f1f5f9 !important;
}

.fep-sticky-col-1 {
  position: sticky;
  left: 40px;
  z-index: 10;
  width: 105px;
  min-width: 105px;
  max-width: 120px;
  background: #ffffff !important;
  box-shadow: 2px 0 4px -2px rgba(0, 0, 0, 0.08);
}
.fep-grid-table thead th.fep-sticky-col-1 {
  z-index: 30;
  background: #f1f5f9 !important;
  width: 105px;
  min-width: 105px;
  max-width: 120px;
  padding: 6px 4px;
  font-size: 11px;
  line-height: 1.2;
}

.fep-sticky-col-2 {
  position: sticky;
  left: 145px;
  z-index: 10;
  width: var(--fep-ref-col-width, 195px);
  min-width: 155px;
  max-width: 235px;
  background: #ffffff !important;
  box-shadow: 3px 0 5px -2px rgba(0, 0, 0, 0.1);
}
.fep-grid-table thead th.fep-sticky-col-2 {
  z-index: 30;
  background: #f1f5f9 !important;
  width: var(--fep-ref-col-width, 195px);
  min-width: 155px;
  max-width: 235px;
}

.fep-t-ref-supplier {
  padding: 4px 5px !important;
  font-size: 12.5px !important;
  font-weight: 600 !important;
}

.fep-product-label {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
  line-height: 1.3;
}

.fep-row-num {
  font-size: 15px;
  font-weight: 800;
  color: #334155;
}

/* Cell inputs */
.fep-cell-input {
  width: 100%;
  box-sizing: border-box;
  padding: 5px 6px;
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #ffffff;
  color: #0f172a;
  text-align: right;
  transition: all 0.15s ease-in-out;
}
.fep-cell-input:focus {
  outline: none;
  border-color: #2563eb;
  background-color: #eff6ff;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}
.fep-cell-input.fep-changed {
  background-color: #fef3c7;
  border-color: #f59e0b;
}

.fep-cell-select {
  width: 100%;
  box-sizing: border-box;
  padding: 4px 6px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: #ffffff;
  color: #0f172a;
}
.fep-cell-select:focus {
  outline: none;
  border-color: #2563eb;
}

/* Values & Badges */
.fep-val-read {
  display: block;
  text-align: right;
  font-size: 13.5px;
  font-weight: 600;
  color: #334155;
  padding: 3px 5px;
}

.fep-val-highlight {
  font-size: 14.5px;
  font-weight: 800;
  color: #0369a1;
}

.fep-t-stock {
  font-size: 15px !important;
  font-weight: 800 !important;
}

.fep-t-suggested-qty {
  font-size: 14px !important;
  font-weight: 800 !important;
}

.fep-t-suggested-sell-price {
  font-size: 14px !important;
  font-weight: 800 !important;
}

.fep-margin-positive {
  color: #059669 !important;
  font-weight: 700 !important;
  font-size: 13px !important;
}
.fep-margin-negative {
  color: #dc2626 !important;
  font-weight: 700 !important;
  font-size: 13px !important;
}

/* Footer summary */
.fep-table-footer {
  background: #f8fafc;
  padding: 10px 18px;
  border-top: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

/* Custom Scrollbar */
.fep-table-scroll-wrap::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
.fep-table-scroll-wrap::-webkit-scrollbar-track {
  background: #f1f5f9;
}
.fep-table-scroll-wrap::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}
.fep-table-scroll-wrap::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

/* Multi-row per product structure */
.fep-badge-cat {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 8px;
  border-radius: 4px;
  min-width: 62px;
  text-align: center;
}
.fep-badge-buy {
  background-color: #dbeafe;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}
.fep-badge-sell {
  background-color: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.fep-th-sub {
  background: #f1f5f9;
  color: #334155;
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
  padding: 6px 6px;
  border-bottom: 1px solid #cbd5e1;
  border-right: 1px solid #e2e8f0;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.fep-th-sub-sell {
  background: #eff6ff;
  color: #1e40af;
  font-size: 11.5px;
  font-weight: 700;
  text-align: center;
  padding: 6px 6px;
  border-bottom: 1px solid #bfdbfe;
  border-right: 1px solid #dbeafe;
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.fep-row-buy td {
  background-color: #ffffff;
  border-bottom: 1px dashed #cbd5e1;
}

.fep-row-sell td {
  background-color: #ffffff;
  border-bottom: 2px solid #64748b !important;
}

.fep-row-buy-head:hover th,
.fep-row-buy:hover td,
.fep-row-sell-head:hover th,
.fep-row-sell:hover td {
  filter: brightness(0.98);
}

.fep-cell-lateral {
  background-color: #ffffff;
  border-bottom: 2px solid #64748b !important;
  vertical-align: middle !important;
}

/* IVA Compra vs IVA Venta conditional formatting */
.fep-vat-equal {
  background-color: #dbeafe !important;
  border-color: #60a5fa !important;
  color: #1e40af !important;
  font-weight: 600 !important;
}

.fep-vat-diff {
  background-color: #fee2e2 !important;
  border-color: #ef4444 !important;
  color: #991b1b !important;
  font-weight: 700 !important;
}

/* Precio Base Compra vs Venta: Fondo rojo y letras blancas si son diferentes */
.fep-price-base-diff {
  background-color: #dc2626 !important;
  color: #ffffff !important;
  border-color: #b91c1c !important;
  font-weight: 700 !important;
}
.fep-price-base-diff:focus {
  background-color: #b91c1c !important;
  color: #ffffff !important;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.4) !important;
}
.fep-price-base-diff option {
  background-color: #ffffff !important;
  color: #0f172a !important;
  font-weight: 500 !important;
}

/* Sugerido de venta vs Precio de venta conditional formatting */
.fep-suggested-cell {
  transition: background-color 0.2s ease, color 0.2s ease;
}

.fep-suggested-ok,
.fep-suggested-above {
  background-color: #dbeafe !important;
}
.fep-suggested-ok .fep-t-suggested-sell-price,
.fep-suggested-above .fep-t-suggested-sell-price {
  color: #1e40af !important;
  font-weight: 700 !important;
}

.fep-suggested-alert,
.fep-suggested-below {
  background-color: #fee2e2 !important;
}
.fep-suggested-alert .fep-t-suggested-sell-price,
.fep-suggested-below .fep-t-suggested-sell-price {
  color: #dc2626 !important;
  font-weight: 700 !important;
}

.fep-price-sell-under {
  border-color: #ef4444 !important;
  background-color: #fff1f2 !important;
  color: #991b1b !important;
  font-weight: 700 !important;
}

/* Precio de venta: Fondo rojo y letras blancas si el sugerido es menor o igual */
.fep-price-sell-red {
  background-color: #dc2626 !important;
  color: #ffffff !important;
  border-color: #b91c1c !important;
  font-weight: 700 !important;
}
.fep-price-sell-red::placeholder {
  color: rgba(255, 255, 255, 0.75) !important;
}
.fep-price-sell-red:focus {
  background-color: #b91c1c !important;
  color: #ffffff !important;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.4) !important;
}

/* Precio de venta: Fondo azul y letras blancas si el sugerido es mayor */
.fep-price-sell-blue {
  background-color: #2563eb !important;
  color: #ffffff !important;
  border-color: #1d4ed8 !important;
  font-weight: 700 !important;
}
.fep-price-sell-blue::placeholder {
  color: rgba(255, 255, 255, 0.75) !important;
}
.fep-price-sell-blue:focus {
  background-color: #1d4ed8 !important;
  color: #ffffff !important;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.4) !important;
}

.fep-price-sell-forbidden {
  border: 2px solid #dc2626 !important;
  background-color: #fef2f2 !important;
  color: #991b1b !important;
  font-weight: 800 !important;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.3) !important;
}

/* Header Info Badges & Tooltip / Popover */
.fep-th-has-info {
  cursor: pointer;
  user-select: none;
}
.fep-info-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #cbd5e1;
  color: #1e293b;
  font-size: 10px;
  font-weight: 800;
  margin-left: 4px;
  cursor: pointer;
  vertical-align: middle;
  transition: all 0.15s ease;
  line-height: 1;
}
.fep-th-has-info:hover .fep-info-badge,
.fep-info-badge:hover {
  background: #2563eb;
  color: #ffffff;
  transform: scale(1.18);
}

.fep-popover-box {
  position: fixed;
  z-index: 999999 !important;
  background: #0f172a;
  color: #f8fafc;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 10px 14px;
  max-width: 300px;
  box-shadow: 0 16px 36px -4px rgba(0, 0, 0, 0.5), 0 6px 14px -2px rgba(0, 0, 0, 0.35);
  font-size: 12px;
  line-height: 1.45;
  pointer-events: auto;
  animation: fep-popover-in 0.15s ease-out;
}
.fep-popover-box.fep-pinned {
  border-color: #3b82f6;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.35), 0 16px 36px -4px rgba(0, 0, 0, 0.55);
}

@keyframes fep-popover-in {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.fep-popover-box .fep-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 5px;
  padding-bottom: 4px;
  border-bottom: 1px solid #334155;
}

.fep-popover-box .fep-popover-title {
  font-size: 12.5px;
  font-weight: 700;
  color: #60a5fa;
}

.fep-popover-box .fep-popover-close {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.fep-popover-box .fep-popover-close:hover {
  color: #ffffff;
}

.fep-popover-box .fep-popover-desc {
  font-size: 12px;
  color: #e2e8f0;
}

/* Auto-compact columns after IVA Compra and Mín. Venta (Cols 7 - 11) */
th.fep-col-compact,
td.fep-col-compact {
  width: 1% !important;
  white-space: nowrap !important;
  padding: 2px 4px !important;
  font-size: 11.5px !important;
  line-height: 1.15 !important;
}

th.fep-col-compact {
  text-align: center !important;
  vertical-align: middle !important;
  white-space: normal !important;
  word-break: normal !important;
}

th.fep-col-compact .fep-info-badge {
  font-size: 9px !important;
  margin-left: 2px !important;
  padding: 0 2px !important;
}

td.fep-col-compact input.fep-cell-input {
  width: 100% !important;
  min-width: 38px !important;
  max-width: 62px !important;
  padding: 2px 4px !important;
  font-size: 11.5px !important;
  height: 25px !important;
}

td.fep-col-compact .fep-val-read {
  padding: 1px 2px !important;
  font-size: 11.5px !important;
  display: inline-block;
  white-space: nowrap !important;
}

td.fep-col-compact .fep-val-highlight {
  font-size: 11.5px !important;
  font-weight: 700 !important;
}

td.fep-col-compact button.fep-t-btn-use-suggested-sell,
td.fep-col-compact button.fep-t-btn-use-suggested {
  padding: 1px 4px !important;
  font-size: 10px !important;
  line-height: 1.2 !important;
}

/* ── Card Modal Native Styles (replacing Tailwind CDN) ──────────────────── */
#fep-overlay {
  position: fixed;
  top: var(--fep-top-offset, 50px);
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(100vh - var(--fep-top-offset, 50px));
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9980;
}
#fep-overlay.hidden {
  display: none !important;
}

#fep-modal {
  position: relative;
  background: #ffffff;
  border-radius: 14px;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 860px;
  margin: 0 16px;
  padding: 24px;
  max-height: 90vh;
  overflow-y: auto;
  box-sizing: border-box;
}

#fep-modal .flex { display: flex; }
#fep-modal .items-center { align-items: center; }
#fep-modal .justify-between { justify-content: space-between; }
#fep-modal .justify-end { justify-content: flex-end; }
#fep-modal .justify-center { justify-content: center; }
#fep-modal .flex-1 { flex: 1 1 0%; }
#fep-modal .flex-wrap { flex-wrap: wrap; }
#fep-modal .gap-1 { gap: 4px; }
#fep-modal .gap-2 { gap: 8px; }
#fep-modal .gap-3 { gap: 12px; }
#fep-modal .gap-4 { gap: 16px; }
#fep-modal .space-y-2 > * + * { margin-top: 8px; }
#fep-modal .space-y-3 > * + * { margin-top: 12px; }
#fep-modal .grid { display: grid; }
#fep-modal .grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 768px) {
  #fep-modal .md\:grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #fep-modal .md\:grid-cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
#fep-modal .hidden { display: none !important; }
#fep-modal input, #fep-modal select { box-sizing: border-box; }


/* Hide number input spinners that overlap right-aligned text */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] {
  -moz-appearance: textfield;
}

/* Fix modal inputs missing Tailwind */
#fep-modal input:not([type="checkbox"]):not([type="radio"]), #fep-modal select { width: 100%; border: 1px solid #d1d5db; border-radius: 0.5rem; padding: 0.5rem 0.75rem; font-size: 0.875rem; color: #1f2937; background-color: #ffffff; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05); text-align: right; box-sizing: border-box; }
#fep-modal input:focus, #fep-modal select:focus { outline: none; border-color: #3b82f6; box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.5); }
#fep-sku { text-align: left !important; }
#fep-buy-comment, #fep-buy-ref-supplier { text-align: left !important; }
#fep-date-start, #fep-date-end { text-align: left !important; }
