/* ============================================================
   pedidos-venta.css - Estilos del modulo Pedidos de Venta
   Tabs, timeline, form crear, detalle — sin hardcode
   ============================================================ */

/* ====== TABS ====== */
.ped-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  margin-bottom: .75rem;
  padding: .5rem;
  background: var(--brand-surface);
  border-radius: 14px;
  border: 1px solid var(--brand-border);
  animation: comFadeUp .4s ease both;
}

.ped-tab {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem .85rem;
  border-radius: 10px;
  border: 1.5px solid transparent;
  background: transparent;
  color: var(--brand-text-muted);
  font-size: .8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .18s;
  white-space: nowrap;
}
.ped-tab:hover {
  background: var(--brand-bg);
  color: var(--brand-text);
}
.ped-tab--active {
  background: var(--brand-accent);
  color: var(--brand-primary);
  border-color: var(--brand-accent);
}
.ped-tab--active:hover {
  background: var(--brand-accent);
  color: var(--brand-primary);
}
.ped-tab__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 10px;
  background: rgba(0,0,0,.08);
  font-size: .68rem;
  font-weight: 700;
}
.ped-tab--active .ped-tab__count {
  background: rgba(0,0,0,.15);
  color: var(--brand-primary);
}

/* ====== BREADCRUMB ====== */
.ped-breadcrumb {
  margin-bottom: .75rem;
}
.ped-breadcrumb a {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  color: var(--brand-text-muted);
  font-size: .82rem;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s;
  text-decoration: none;
}
.ped-breadcrumb a:hover {
  color: var(--brand-accent);
}

/* ====== FORM GRID (nuevo pedido) ====== */
.ped-form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: .75rem;
}
@media (min-width: 960px) {
  .ped-form-grid {
    grid-template-columns: 380px 1fr;
  }
}

/* Fix: paneles con buscador deben permitir overflow para dropdowns */
.ped-form-grid .panel {
  overflow: visible;
}
.ped-form-grid .panel-body {
  overflow: visible;
}
.ped-form-grid .com-search-wrap {
  position: relative;
  z-index: 50;
}
.ped-form-grid .com-search-wrap .com-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--brand-surface);
  border: 1.5px solid var(--brand-border);
  border-radius: 14px;
  max-height: 280px;
  overflow-y: auto;
  z-index: 9999;
  box-shadow: 0 12px 40px rgba(0,0,0,.22), 0 4px 12px rgba(0,0,0,.08);
  display: none;
}
.ped-form-grid .com-search-wrap .com-dropdown.com-dropdown--open {
  display: block;
  animation: comSlideDown .2s ease;
}
.ped-form-grid .com-dropdown .com-dropdown__item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--brand-border);
  cursor: pointer;
  transition: background .12s;
  font-size: .84rem;
  background: var(--brand-surface);
  color: var(--brand-text);
}
.ped-form-grid .com-dropdown .com-dropdown__item:hover {
  background: rgba(147,193,31,.08);
}
.ped-form-grid .com-dropdown .com-dropdown__item:last-child {
  border-bottom: none;
}
.ped-form-grid .com-dropdown .com-dropdown__item strong {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: .78rem;
  color: var(--brand-text-muted);
  background: var(--brand-bg);
  padding: .15rem .45rem;
  border-radius: 5px;
  border: 1px solid var(--brand-border);
  flex-shrink: 0;
}

/* ====== CLIENTE CARD ====== */
/* Z-index para que dropdown de cliente no quede bajo panel de productos */
.ped-form-left {
  position: relative;
  z-index: 10;
}
.ped-form-right {
  position: relative;
  z-index: 5;
}
.ped-cli-card {
  margin-top: .75rem;
  animation: comFadeUp .3s ease both;
}
.ped-cli-info {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .85rem;
  background: var(--brand-bg);
  border-radius: 12px;
  border: 1px solid var(--brand-border);
  position: relative;
}
.ped-cli-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--brand-accent);
  color: var(--brand-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
}
.ped-cli-name {
  font-weight: 700;
  font-size: .9rem;
}
.ped-cli-meta {
  font-size: .76rem;
  color: var(--brand-text-muted);
  margin-top: 2px;
}
.ped-cli-meta i {
  margin-right: 2px;
}
.ped-cli-remove {
  position: absolute;
  top: .5rem;
  right: .5rem;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--brand-border);
  background: var(--brand-surface);
  color: var(--brand-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .72rem;
  transition: all .15s;
}
.ped-cli-remove:hover {
  color: var(--brand-error);
  border-color: var(--brand-error);
}

/* ====== DATOS DE ENTREGA ====== */
.ped-cli-entrega {
  margin-top: .75rem;
  padding: .85rem;
  background: var(--brand-bg);
  border-radius: 12px;
  border: 1px solid var(--brand-border);
  border-left: 3px solid var(--brand-primary);
}
.ped-cli-entrega-title {
  font-weight: 700;
  font-size: .82rem;
  color: var(--brand-primary);
  margin-bottom: .6rem;
}
.ped-cli-entrega-title i {
  margin-right: .35rem;
}
.ped-cli-entrega-fields {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
}
.ped-cli-entrega-fields .com-label {
  font-size: .72rem;
  font-weight: 600;
  color: var(--brand-text-muted);
  margin-bottom: .25rem;
  display: block;
}
.ped-cli-entrega-fields .form-input {
  width: 100%;
  font-size: .82rem;
}
@media (max-width: 600px) {
  .ped-cli-entrega-fields {
    flex-direction: column;
  }
  .ped-cli-entrega-fields > div {
    flex: 1 1 100% !important;
    min-width: 0 !important;
  }
}

/* ====== PRIORIDAD BUTTONS ====== */
.ped-prioridad-btns {
  display: flex;
  gap: .5rem;
}
.ped-prio-btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .45rem .85rem;
  border-radius: 8px;
  border: 1.5px solid var(--brand-border);
  background: var(--brand-surface);
  color: var(--brand-text-muted);
  font-size: .8rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
}
.ped-prio-btn:hover {
  border-color: var(--brand-accent);
}
.ped-prio-btn--active {
  border-color: var(--brand-accent);
  background: rgba(147,193,31,.1);
  color: var(--brand-text);
}
.ped-prio-btn--active[data-prio="urgente"] {
  border-color: var(--brand-error);
  background: #fef2f2;
  color: var(--brand-error);
}

/* ====== PRODUCT ADD ROW (search + lista inline) ====== */
.ped-add-product-row {
  display: flex;
  gap: .5rem;
  align-items: flex-start;
}
.ped-lista-inline {
  flex-shrink: 0;
  width: 110px;
  padding: .5rem .6rem;
  font-size: .78rem;
}
.ped-item-lista-sel {
  border-radius: 6px;
  border: 1px solid var(--brand-border);
  background: var(--brand-bg);
}

/* ====== ITEMS LIST (form) ====== */
.ped-items-list {
  max-height: 400px;
  overflow-y: auto;
}
.ped-empty-items {
  text-align: center;
  padding: 2rem;
  color: var(--brand-text-muted);
}
.ped-empty-items i {
  font-size: 2rem;
  display: block;
  margin-bottom: .5rem;
  opacity: .4;
}
.ped-item-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
  padding: .65rem .75rem;
  border-bottom: 1px solid var(--brand-border);
  animation: comFadeUp .25s ease both;
}
.ped-item-row:last-child {
  border-bottom: none;
}
.ped-item-info {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex: 1;
  min-width: 0;
}
.ped-item-code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: .72rem;
  color: var(--brand-text-muted);
  background: var(--brand-bg);
  padding: .15rem .4rem;
  border-radius: 4px;
  border: 1px solid var(--brand-border);
  flex-shrink: 0;
}
.ped-item-name {
  font-weight: 600;
  font-size: .82rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ped-item-ref {
  font-size: .72rem;
  color: var(--brand-text-muted);
  flex-shrink: 0;
}
.ped-item-controls {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}
.ped-item-field {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.ped-item-field label {
  font-size: .62rem;
  text-transform: uppercase;
  color: var(--brand-text-muted);
  font-weight: 600;
  letter-spacing: .03em;
}
.ped-item-field input {
  width: 60px;
  padding: 4px 6px;
  text-align: center;
  font-size: .82rem;
}
.ped-item-price, .ped-item-subtotal {
  font-size: .82rem;
  font-weight: 600;
  white-space: nowrap;
}
.ped-item-remove {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--brand-border);
  background: transparent;
  color: var(--brand-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .72rem;
  transition: all .15s;
}
.ped-item-remove:hover {
  color: #ef4444;
  border-color: #fca5a5;
  background: #fef2f2;
}
.ped-item-count {
  font-size: .78rem;
  color: var(--brand-text-muted);
  font-weight: 500;
}

/* ====== RESUMEN ====== */
.ped-resumen .panel-body {
  padding: 1rem 1.25rem;
}
.ped-res-row {
  display: flex;
  justify-content: space-between;
  padding: .35rem 0;
  font-size: .88rem;
  color: var(--brand-text-muted);
}
.ped-res-total {
  padding-top: .65rem;
  margin-top: .35rem;
  border-top: 2px solid var(--brand-border);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--brand-text);
}

/* ====== DETALLE HEADER ====== */
.ped-det-header {
  margin-bottom: 1rem;
}
.ped-det-title {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}
.ped-det-title h2 {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--brand-text);
  margin: 0;
}
.ped-det-date {
  font-size: .8rem;
  color: var(--brand-text-muted);
  margin-top: .25rem;
}

.ped-det-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: .75rem;
}
@media (min-width: 960px) {
  .ped-det-grid {
    grid-template-columns: 340px 1fr;
  }
}

/* ====== TIMELINE ====== */
.ped-timeline {
  position: relative;
  padding: 1.25rem 1rem;
  margin-bottom: 1rem;
  background: var(--brand-surface);
  border-radius: 14px;
  border: 1px solid var(--brand-border);
  animation: comFadeUp .5s ease both;
}
.ped-tl-track {
  position: absolute;
  top: 50%;
  left: 2rem;
  right: 2rem;
  height: 3px;
  background: var(--brand-border);
  border-radius: 2px;
  transform: translateY(-50%);
  z-index: 0;
}
.ped-tl-progress {
  height: 100%;
  background: var(--brand-accent);
  border-radius: 2px;
  transition: width .6s ease;
}
.ped-tl-steps {
  display: flex;
  justify-content: space-between;
  position: relative;
  z-index: 1;
}
.ped-tl-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .35rem;
}
.ped-tl-dot {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--brand-bg);
  border: 2px solid var(--brand-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .72rem;
  color: var(--brand-text-muted);
  transition: all .3s;
}
.ped-tl-step--done .ped-tl-dot {
  background: var(--brand-accent);
  border-color: var(--brand-accent);
  color: var(--brand-primary);
}
.ped-tl-step--current .ped-tl-dot {
  box-shadow: 0 0 0 4px rgba(147,193,31,.25);
  transform: scale(1.1);
}
.ped-tl-label {
  font-size: .66rem;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--brand-text-muted);
  letter-spacing: .03em;
}
.ped-tl-step--done .ped-tl-label,
.ped-tl-step--current .ped-tl-label {
  color: var(--brand-text);
}

/* ====== ALERTS ====== */
.ped-alert {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: 1rem 1.25rem;
  border-radius: 12px;
  margin-bottom: 1rem;
  font-size: .88rem;
  animation: comFadeUp .4s ease both;
}
.ped-alert i {
  font-size: 1.1rem;
  margin-top: 2px;
}
.ped-alert--danger {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: #991b1b;
}
.ped-alert--danger i {
  color: #dc2626;
}
.ped-alert--muted {
  background: #f3f4f6;
  border: 1px solid #d1d5db;
  color: #4b5563;
}
.ped-alert p {
  margin: .25rem 0 0;
  font-size: .82rem;
}

/* ====== TRAZABILIDAD ====== */
.ped-trace-list {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.ped-trace-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .82rem;
  color: var(--brand-text);
}
.ped-trace-item i {
  width: 20px;
  text-align: center;
  color: var(--brand-text-muted);
  font-size: .78rem;
}

/* ====== ACCIONES ====== */
.ped-acciones {
  padding: 1rem;
  background: var(--brand-surface);
  border-radius: 14px;
  border: 1px solid var(--brand-border);
}
.ped-acciones-btns {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
}
.ped-rechazo-wrap {
  margin-bottom: .75rem;
  animation: comFadeUp .3s ease both;
}

/* ====== BUTTON VARIANTS ====== */
.btn-info { background: #0EA5E9; color: #fff; }
.btn-info:hover:not(:disabled) { background: #0284c7; }
.btn-danger { background: #DC2626; color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-purple { background: #8B5CF6; color: #fff; }
.btn-purple:hover:not(:disabled) { background: #7c3aed; }

/* ====== COM-INFO-GRID ====== */
.com-info-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: .6rem;
}
.com-info-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ====== BADGES EXTRA ====== */
.com-badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  white-space: nowrap;
}
.com-badge--warn { background: #fef9c3; color: #92400e; }
.com-badge--info { background: #e0f2fe; color: #075985; }
.com-badge--danger { background: #fee2e2; color: #991b1b; }
.com-badge--purple { background: #ede9fe; color: #5b21b6; }
.com-badge--ok { background: #dcfce7; color: #166534; }
.com-badge--primary { background: rgba(8,71,52,.1); color: #084734; }
.com-badge--muted { background: #f3f4f6; color: #6b7280; }

/* ====== COM-CHIP (small label) ====== */
.com-chip {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--brand-bg);
  color: var(--brand-text-muted);
  font-size: .7rem;
  font-weight: 500;
  border: 1px solid var(--brand-border);
}

/* ====== TABLE WRAP ====== */
.com-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.com-tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: .84rem;
}
.com-tbl th {
  padding: .6rem .75rem;
  text-align: left;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--brand-text-muted);
  border-bottom: 2px solid var(--brand-border);
  white-space: nowrap;
}
.com-tbl td {
  padding: .65rem .75rem;
  border-bottom: 1px solid var(--brand-border);
  vertical-align: middle;
}

/* ====== SKELETON ====== */
.com-sk { padding: 1rem; }
.com-sk__bar { height: 16px; background: var(--brand-bg); border-radius: 8px; margin-bottom: 1rem; animation: comPulse 1.5s infinite; }
.com-sk__bar--lg { width: 60%; height: 20px; }
.com-sk__grid { display: grid; grid-template-columns: repeat(4,1fr); gap: .75rem; margin-bottom: 1rem; }
.com-sk__card { height: 60px; background: var(--brand-bg); border-radius: 10px; animation: comPulse 1.5s infinite; }
.com-sk__lines { display: flex; flex-direction: column; gap: .5rem; }
.com-sk__line { height: 14px; background: var(--brand-bg); border-radius: 6px; animation: comPulse 1.5s infinite; }
.com-sk__line:nth-child(odd) { width: 90%; }
.com-sk__line:nth-child(even) { width: 70%; }

@keyframes comPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}
@keyframes comFadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ====== KPI STRIP ====== */
.com-kpi-strip {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .5rem;
  margin-bottom: .75rem;
}
@media (min-width: 769px) {
  .com-kpi-strip {
    grid-template-columns: repeat(4, 1fr);
  }
}
.com-kpi {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .75rem 1rem;
  background: var(--brand-surface);
  border-radius: 12px;
  border: 1px solid var(--brand-border);
  animation: comFadeUp .4s ease both;
}

/* ====== RESPONSIVE ====== */
@media (max-width: 768px) {
  .ped-tabs {
    gap: .25rem;
    padding: .35rem;
  }
  .ped-tab {
    padding: .4rem .6rem;
    font-size: .72rem;
  }
  .ped-tl-dot {
    width: 28px;
    height: 28px;
    font-size: .62rem;
  }
  .ped-tl-label {
    font-size: .58rem;
  }
  .ped-det-title h2 {
    font-size: 1.05rem;
  }
  .ped-item-controls {
    width: 100%;
    justify-content: flex-end;
  }
  .com-kpi-strip {
    grid-template-columns: repeat(2, 1fr);
  }
  .ped-items-table {
    font-size: .7rem;
  }
  .ped-items-table th,
  .ped-items-table td {
    padding: .3rem .25rem;
  }
  .ped-tbl-qty,
  .ped-tbl-precio,
  .ped-tbl-dcto {
    width: 55px;
    font-size: .7rem;
  }
  .ped-tbl-lista {
    font-size: .68rem;
    min-width: 65px;
  }
  .ped-td-name {
    max-width: 120px;
  }
}

/* ====== TABLA ITEMS PEDIDO (edición inline) ====== */
.ped-items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .78rem;
}
.ped-items-table thead th {
  text-align: left;
  font-size: .66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .3px;
  color: var(--brand-text-muted);
  padding: .45rem .35rem;
  border-bottom: 2px solid var(--brand-border);
  white-space: nowrap;
}
.ped-items-table tbody tr {
  border-bottom: 1px solid var(--brand-border);
  transition: background .15s;
}
.ped-items-table tbody tr:hover {
  background: var(--brand-surface);
}
.ped-items-table tbody tr.ped-obs-row {
  border-bottom: 1px solid var(--brand-border);
  background: var(--brand-bg);
}
.ped-items-table tbody tr.ped-obs-row:hover {
  background: var(--brand-bg);
}
.ped-items-table td {
  padding: .4rem .35rem;
  vertical-align: middle;
}
.ped-td-code {
  font-weight: 600;
  font-family: 'JetBrains Mono', monospace;
  font-size: .72rem;
  color: var(--brand-text-muted);
  white-space: nowrap;
}
.ped-td-name {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
.ped-td-name div:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ped-td-obs-preview {
  font-size: .68rem;
  color: var(--brand-text-muted);
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ped-td-obs-preview i {
  color: var(--brand-primary);
  margin-right: 2px;
  font-size: .62rem;
}
.ped-td-subtotal {
  text-align: right;
  white-space: nowrap;
}

/* Inputs inline en tabla */
.ped-tbl-qty,
.ped-tbl-precio,
.ped-tbl-dcto {
  width: 65px;
  text-align: right;
  padding: .3rem .35rem;
  font-size: .76rem;
}
.ped-tbl-precio {
  width: 80px;
}
.ped-tbl-dcto {
  width: 50px;
}
.ped-tbl-lista {
  font-size: .72rem;
  padding: .25rem .3rem;
  min-width: 80px;
}

/* Stock badge */
.ped-stock-badge {
  display: inline-block;
  font-size: .72rem;
  font-weight: 700;
  padding: .15rem .45rem;
  border-radius: 6px;
  background: var(--brand-accent, #dbeafe);
  color: var(--brand-primary, #2563eb);
}
.ped-stock-badge--zero {
  background: #fef2f2;
  color: #dc2626;
}

/* Acciones por fila (obs + eliminar) */
.ped-tbl-actions {
  display: flex;
  gap: .25rem;
  align-items: center;
}
.ped-item-obs-btn {
  padding: .2rem .35rem;
  font-size: .68rem;
  background: transparent;
  border: 1px solid var(--brand-border);
  border-radius: 6px;
  color: var(--brand-text-muted);
  cursor: pointer;
  transition: all .15s;
}
.ped-item-obs-btn:hover {
  color: var(--brand-primary);
  border-color: var(--brand-primary);
}
.ped-items-table .ped-item-remove {
  padding: .2rem .35rem;
  font-size: .68rem;
}

/* Fila de observación inline */
.ped-obs-inline {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .15rem 0;
}
.ped-obs-inline i {
  color: var(--brand-primary);
  font-size: .72rem;
  flex-shrink: 0;
}
.ped-obs-inline .form-input {
  flex: 1;
  font-size: .76rem;
  padding: .3rem .45rem;
}
