/* ═══════════════════════════════════════════════════════════════════════ */
/* MÓDULO FACTURACIÓN — HISTORIAL + EDITOR                                 */
/* ═══════════════════════════════════════════════════════════════════════ */

/* ═══ HISTORIAL MODERNO ═══ */
.hist-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 14px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 10px;
  border: 1px solid #e8edf2;
}
.hist-filtros {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.hist-fb {
  background: #fff;
  border: 1.5px solid #e8edf2;
  color: #64748b;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all .2s;
}
.hist-fb:hover {
  border-color: #F5923A;
  color: #F5923A;
}
.hist-fb.on {
  background: #F5923A;
  border-color: #F5923A;
  color: #fff;
}
.hist-buscar {
  display: flex;
  gap: 6px;
}
.hist-buscar input[type="text"] {
  width: 200px;
  border: 1.5px solid #e8edf2;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  outline: none;
}
.hist-buscar input[type="date"] {
  border: 1.5px solid #e8edf2;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
  outline: none;
}
.hist-buscar input:focus {
  border-color: #F5923A;
}

/* ═══ STATS RESUMEN ═══ */
.hist-resumen {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.hist-stat {
  background: #fff;
  border: 1.5px solid #e8edf2;
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  flex: 1;
  text-align: center;
}
.hist-stat strong {
  font-size: 18px;
  font-weight: 800;
  color: #0A2540;
  line-height: 1;
  font-family: 'Sora', sans-serif;
}
.hist-stat span {
  font-size: 10px;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-top: 4px;
}

/* ═══ LISTA ═══ */
.hist-lista {
  background: #fff;
  border: 1px solid #e8edf2;
  border-radius: 12px;
  overflow: hidden;
}
.hist-row {
  display: grid;
  grid-template-columns: 130px 1fr 180px 140px 200px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  gap: 12px;
  transition: background .15s;
}
.hist-row:hover {
  background: #fff8f1;
}
.hist-row:last-child {
  border-bottom: none;
}
.hist-col-num strong {
  display: block;
  font-size: 13px;
  color: #F5923A;
  font-weight: 800;
  font-family: 'Sora', sans-serif;
}
.hist-col-num small {
  font-size: 10px;
  color: #94a3b8;
}
.hist-col-cli strong {
  display: block;
  font-size: 13px;
  color: #0A2540;
  font-weight: 700;
}
.hist-col-cli small {
  font-size: 10px;
  color: #94a3b8;
}
.hist-col-info {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.hist-badge {
  background: #64748b;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 30px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.hist-col-total {
  text-align: right;
}
.hist-col-total strong {
  font-size: 14px;
  color: #0A2540;
  font-weight: 800;
  font-family: 'Sora', sans-serif;
}
.hist-col-acc {
  display: flex;
  gap: 3px;
  justify-content: flex-end;
}
.hist-btn {
  background: #f1f5f9;
  border: none;
  width: 30px;
  height: 30px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.hist-btn:hover {
  background: #e2e8f0;
  transform: translateY(-1px);
}

.hist-empty {
  padding: 60px 20px;
  text-align: center;
  color: #94a3b8;
  font-size: 14px;
}
.hist-loading {
  padding: 60px 20px;
  text-align: center;
  color: #94a3b8;
}
.hist-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e8edf2;
  border-top-color: #F5923A;
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: histSpin .8s linear infinite;
}
@keyframes histSpin { to { transform: rotate(360deg); } }

/* ═══ EDITOR DE VENTA RICA ═══ */
.modal-edit-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10,37,64,.7);
  backdrop-filter: blur(4px);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: editFadeIn .2s ease;
}
@keyframes editFadeIn { from{opacity:0} to{opacity:1} }

.modal-edit-box {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,.3);
}
.modal-edit-header {
  padding: 16px 22px;
  border-bottom: 1px solid #e8edf2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(135deg, #f8fafc, #fff);
}
.modal-edit-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 800;
  color: #0A2540;
  font-family: 'Sora', sans-serif;
}
.modal-edit-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px 22px;
}
.modal-edit-footer {
  padding: 14px 22px;
  border-top: 1px solid #e8edf2;
  background: #f8fafc;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.edit-section {
  margin-bottom: 20px;
}
.edit-section h3 {
  font-size: 13px;
  font-weight: 800;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 10px;
  font-family: 'Sora', sans-serif;
}
.edit-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}
.edit-group label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: #64748b;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.edit-group input,
.edit-group select,
.modal-edit-body textarea {
  width: 100%;
  border: 1.5px solid #e8edf2;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border .2s;
  background: #fff;
}
.edit-group input:focus,
.edit-group select:focus,
.modal-edit-body textarea:focus {
  border-color: #F5923A;
}

/* Items editables */
.edit-item-row {
  background: #f8fafc;
  border: 1px solid #e8edf2;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 8px;
}
.edit-item-nombre {
  margin-bottom: 8px;
}
.edit-item-nombre strong {
  font-size: 13px;
  color: #0A2540;
  display: block;
}
.edit-item-nombre small {
  font-size: 10px;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.edit-item-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 40px;
  gap: 8px;
  align-items: end;
}
.edit-item-grid label {
  display: block;
  font-size: 9px;
  font-weight: 700;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 3px;
}
.edit-item-grid input {
  width: 100%;
  border: 1.5px solid #e8edf2;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
  text-align: center;
  font-weight: 700;
  outline: none;
}
.edit-item-grid input:focus {
  border-color: #F5923A;
}
.edit-item-sub {
  font-size: 13px;
  font-weight: 800;
  color: #F5923A;
  text-align: right;
  padding: 6px 0;
}
.btn-edit-delete {
  background: #fee2e2;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  padding: 6px;
  height: 32px;
  transition: all .15s;
}
.btn-edit-delete:hover {
  background: #fecaca;
  transform: scale(1.05);
}

.edit-total {
  font-size: 14px;
  font-weight: 700;
  color: #64748b;
}
.edit-total span {
  font-size: 19px;
  font-weight: 800;
  color: #F5923A;
  font-family: 'Sora', sans-serif;
}
.btn-edit {
  border: none;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  margin-left: 6px;
  transition: all .2s;
}
.btn-edit-primary {
  background: #F5923A;
  color: #fff;
}
.btn-edit-primary:hover {
  background: #e07e28;
}
.btn-edit-ghost {
  background: #f1f5f9;
  color: #64748b;
}
.btn-edit-ghost:hover {
  background: #e2e8f0;
}

/* ═══ MOBILE ═══ */
@media (max-width: 768px) {
  .hist-row {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .hist-col-num, .hist-col-cli {
    grid-column: 1 / -1;
  }
  .hist-col-info {
    justify-content: flex-start;
  }
  .hist-col-total {
    text-align: right;
  }
  .hist-col-acc {
    grid-column: 1 / -1;
    justify-content: center;
    padding-top: 6px;
    border-top: 1px dashed #e8edf2;
  }
  .modal-edit-box {
    max-height: 100vh;
    border-radius: 0;
  }
  .edit-row {
    grid-template-columns: 1fr;
  }
  .edit-item-grid {
    grid-template-columns: 1fr 1fr;
  }
  .hist-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .hist-buscar {
    flex-direction: column;
  }
  .hist-buscar input[type="text"] {
    width: 100%;
  }
}


/* ═══════════════════════════════════════════════════════════════════════ */
/* MEJORAS RESPONSIVE COMPLETAS                                            */
/* ═══════════════════════════════════════════════════════════════════════ */

/* ═══ NAVEGACIÓN BUSCADOR PRODUCTOS — Item resaltado por teclado ═══ */
.dd-item.dd-item-sel {
  background: linear-gradient(90deg, #fff4ec, #fff8f1) !important;
  border-left: 3px solid #F5923A !important;
  padding-left: 10px;
}
.dd-item {
  transition: all 0.15s ease;
}

/* ═══ TABLAS RESPONSIVE — Convertir a cards en móvil ═══ */
@media (max-width: 640px) {
  /* Historial - filas en cards verticales */
  .hist-row {
    display: block !important;
    padding: 14px !important;
    border-radius: 10px;
    margin-bottom: 8px;
    background: #fff !important;
    border: 1px solid #e8edf2;
    box-shadow: 0 2px 6px rgba(10,37,64,.04);
  }
  .hist-row:hover {
    background: #fff8f1 !important;
  }
  .hist-col-num,
  .hist-col-cli,
  .hist-col-info,
  .hist-col-total,
  .hist-col-acc {
    display: block !important;
    width: 100% !important;
    text-align: left !important;
    margin-bottom: 8px;
    grid-column: unset !important;
  }
  .hist-col-num strong {
    font-size: 16px;
    display: inline-block;
    margin-right: 8px;
  }
  .hist-col-num small {
    font-size: 12px;
    color: #94a3b8;
  }
  .hist-col-cli strong {
    font-size: 14px;
  }
  .hist-col-total {
    text-align: right !important;
    margin-top: -8px !important;
  }
  .hist-col-total strong {
    font-size: 18px;
    color: #F5923A;
  }
  .hist-col-acc {
    justify-content: center !important;
    border-top: 1px dashed #e8edf2;
    padding-top: 10px !important;
    margin-top: 8px !important;
    display: flex !important;
    flex-wrap: wrap;
    gap: 6px;
  }
  .hist-btn {
    min-width: 44px;
    min-height: 44px;
    font-size: 18px;
  }

  /* Filtros del historial: scroll horizontal limpio */
  .hist-toolbar {
    padding: 10px !important;
    gap: 8px;
  }
  .hist-filtros {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .hist-filtros::-webkit-scrollbar { display: none; }
  .hist-fb {
    flex-shrink: 0;
    padding: 8px 14px;
    font-size: 13px;
    min-height: 38px;
  }
  .hist-buscar {
    width: 100%;
  }
  .hist-buscar input[type="text"],
  .hist-buscar input[type="date"] {
    width: 100% !important;
    font-size: 16px; /* evita zoom en iOS */
    min-height: 42px;
  }

  /* Stats compactos en móvil */
  .hist-resumen {
    gap: 6px;
  }
  .hist-stat {
    padding: 8px 10px;
  }
  .hist-stat strong {
    font-size: 15px;
  }
  .hist-stat span {
    font-size: 9px;
  }

  /* Editor de venta rica - mejoras móvil */
  .modal-edit-box {
    border-radius: 0 !important;
    max-height: 100vh !important;
    height: 100vh;
    max-width: 100% !important;
  }
  .modal-edit-header h2 {
    font-size: 15px;
  }
  .modal-edit-body {
    padding: 16px;
  }
  .edit-row {
    grid-template-columns: 1fr !important;
    gap: 8px;
  }
  .edit-item-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px;
  }
  .edit-item-grid > div:last-child {
    grid-column: 1 / -1;
    text-align: center;
  }
  .btn-edit-delete {
    width: 100%;
    height: 38px;
  }
  .modal-edit-footer {
    flex-direction: column;
    gap: 10px;
    padding: 12px 16px;
  }
  .modal-edit-footer > div {
    width: 100%;
    display: flex;
    gap: 6px;
  }
  .btn-edit {
    flex: 1;
    padding: 12px;
    margin-left: 0;
  }
  .edit-total {
    text-align: center;
    width: 100%;
  }
}

/* ═══ INPUTS GENÉRICOS — evita zoom en iOS al focusear ═══ */
@media (max-width: 640px) {
  input[type="text"],
  input[type="number"],
  input[type="email"],
  input[type="tel"],
  input[type="date"],
  input[type="search"],
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* ═══ BUSCADOR DE PRODUCTOS — dropdown más legible en móvil ═══ */
@media (max-width: 640px) {
  .dd-item {
    padding: 12px 14px !important;
    min-height: 48px;
    line-height: 1.4;
  }
  .dropdown-lista {
    max-height: 50vh !important;
  }
}

/* ═══ BOTONES TOUCH-FRIENDLY ═══ */
@media (max-width: 640px) {
  button,
  .btn {
    min-height: 42px;
    touch-action: manipulation;
  }
  .btn-sm {
    min-height: 36px;
  }
}
