/* ==================== */
/*  FORMULARIO          */
/* ==================== */
#presupuestoFormulario {
  max-width: 700px;
  margin: 0 auto;
  background: #fff;
  padding: 25px;
  border-radius: 8px;
  box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
}

#presupuestoFormulario h2 {
  text-align: center;
  color: #0073aa;
  margin-bottom: 25px;
  padding-bottom: 15px;
  border-bottom: 2px solid #f0f0f0;
}

#presupuestoFormulario label {
  display: block;
  margin-top: 15px;
  font-weight: bold;
  color: #333;
  font-size: 14px;
}

#presupuestoFormulario input,
#presupuestoFormulario textarea,
#presupuestoFormulario select {
  width: 100%;
  padding: 10px 12px;
  margin-top: 5px;
  border: 1px solid #ddd;
  border-radius: 5px;
  box-sizing: border-box;
  font-size: 14px;
  font-family: inherit;
}

#presupuestoFormulario input:focus,
#presupuestoFormulario textarea:focus,
#presupuestoFormulario select:focus {
  border-color: #0073aa;
  box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.1);
  outline: none;
}

/* Grid para formulario */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
  margin-bottom: 10px;
}

.form-buttons {
  margin-top: 25px;
  text-align: center;
}

#generarPresupuesto {
  background: linear-gradient(135deg, #0073aa 0%, #005a8c 100%);
  color: white;
  border: none;
  padding: 12px 30px;
  border-radius: 5px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  width: 100%;
  max-width: 300px;
}

#generarPresupuesto:hover {
  background: linear-gradient(135deg, #005a8c 0%, #004670 100%);
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 115, 170, 0.3);
}

#generarPresupuesto:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* Campos de cantidad */
#contenedor-cantidades {
  margin-top: 15px;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 5px;
  border: 1px solid #e9ecef;
}

#contenedor-cantidades h4 {
  margin-top: 0;
  margin-bottom: 10px;
  color: #495057;
  font-size: 15px;
}

.campo-cantidad {
  margin-bottom: 10px;
  padding: 8px;
  background: white;
  border-radius: 4px;
  border: 1px solid #dee2e6;
}

.campo-cantidad label {
  margin-top: 0;
  font-weight: normal;
  color: #666;
  font-size: 13px;
  margin-bottom: 5px;
}

.cantidad-producto {
  width: 70px !important;
  text-align: center;
  padding: 6px !important;
  font-size: 14px;
}

/* ==================== */
/*  PRESUPUESTO         */
/* ==================== */
.presupuesto-contenido {
  max-width: 800px;
  margin: 0 auto;
  background: white;
  padding: 20px;
}

/* Cabecera compacta */
.presupuesto-header {
  margin-bottom: 25px;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 15px;
  padding-bottom: 15px;
  border-bottom: 2px solid #0073aa;
}

.logo-header {
  width: 180px;
  height: auto;
}

.presupuesto-info {
  text-align: right;
}

.presupuesto-info h1 {
  margin: 0;
  color: #0073aa;
  font-size: 28px;
  font-weight: bold;
}

.numero-presupuesto {
  font-size: 16px;
  color: #666;
  font-weight: normal;
  margin-top: 5px;
}

/* Datos en una columna (no grid) */
.datos-cliente,
.datos-presupuesto {
  margin-bottom: 20px;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 5px;
  border-left: 4px solid #0073aa;
}

.datos-cliente h3,
.datos-presupuesto h3 {
  margin-top: 0;
  margin-bottom: 10px;
  color: #333;
  font-size: 16px;
}

.datos-cliente p,
.datos-presupuesto p {
  margin: 5px 0;
  font-size: 14px;
}

.detalle-titulo {
  color: #333;
  font-size: 18px;
  margin-top: 25px;
  margin-bottom: 15px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eee;
}

/* Tabla optimizada para impresión */
.presupuesto-tabla {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 13px;
}

.presupuesto-tabla th {
  background: #f8f9fa;
  color: #333;
  font-weight: 600;
  padding: 10px 8px;
  text-align: left;
  border-bottom: 2px solid #0073aa;
  font-size: 13px;
}

.presupuesto-tabla td {
  padding: 8px;
  border-bottom: 1px solid #eee;
  vertical-align: middle;
}

/* Columnas optimizadas */
.producto-col {
  width: 50%;
}

.cantidad-col {
  width: 10%;
  text-align: center;
  white-space: nowrap;
}

.precio-col {
  width: 20%;
  text-align: right;
  white-space: nowrap;
}

.subtotal-col {
  width: 20%;
  text-align: right;
  white-space: nowrap;
  font-weight: bold;
}

.thumb-producto {
  width: 30px;
  height: 30px;
  object-fit: contain;
  margin-right: 8px;
  vertical-align: middle;
  border-radius: 3px;
}

/* Descuento */
.descuento-fila {
  text-align: right !important;
  font-size: 13px;
  padding: 8px !important;
}

/* Políticas de descuento */
.descuento-efectivo {
  background-color: #e8f5e9 !important;
  color: #2e7d32 !important;
}
.descuento-promocional {
  background-color: #e3f2fd !important;
  color: #1565c0 !important;
}
.descuento-gremio {
  background-color: #fff3e0 !important;
  color: #ef6c00 !important;
}
.descuento-mayorista {
  background-color: #f3e5f5 !important;
  color: #7b1fa2 !important;
}
.descuento-obras {
  background-color: #ffebee !important;
  color: #c62828 !important;
}

/* Total */
.total-container {
  text-align: right;
  margin: 25px 0;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 5px;
  border: 1px solid #0073aa;
}

.total {
  margin: 0;
  color: #0073aa;
  font-size: 24px;
}

/* Observaciones */
.observaciones {
  margin: 20px 0;
  padding: 15px;
  background: #fff8e1;
  border-radius: 5px;
  border-left: 4px solid #ffc107;
}

.observaciones h4 {
  margin-top: 0;
  margin-bottom: 8px;
  color: #856404;
}

.observaciones p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

/* Footer */
.presupuesto-footer {
  text-align: center;
  margin-top: 30px;
  padding-top: 20px;
  border-top: 2px solid #eee;
  font-size: 12px;
  line-height: 1.4;
}

.presupuesto-footer p {
  color: #666;
  margin: 4px 0;
}

.presupuesto-footer strong {
  color: #0073aa;
  font-size: 13px;
}

.presupuesto-footer a {
  color: #0073aa;
  text-decoration: none;
}

.presupuesto-footer a:hover {
  text-decoration: underline;
}

.logo-footer {
  width: 200px;
  height: auto;
  margin-bottom: 10px;
}

/* Botones de acción en presupuesto */
.acciones-post {
  margin-top: 30px;
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.acciones-post button {
  padding: 12px 20px;
  border: none;
  border-radius: 5px;
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: all 0.3s ease;
  min-width: 180px;
}

.btn-imprimir {
  background: #0073aa;
}
.btn-correo {
  background: #28a745;
}
.btn-nuevo {
  background: #6c757d;
}

.btn-imprimir:hover {
  background: #005a8c;
  transform: translateY(-2px);
}
.btn-correo:hover {
  background: #218838;
  transform: translateY(-2px);
}
.btn-nuevo:hover {
  background: #545b62;
  transform: translateY(-2px);
}

/* ==================== */
/*  MODAL               */
/* ==================== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
}

.modal-content {
  background: #fff;
  padding: 25px;
  border-radius: 8px;
  width: 350px;
  max-width: 90%;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.modal-content h3 {
  margin-top: 0;
  margin-bottom: 15px;
  color: #333;
}

.modal-content label {
  display: block;
  margin-bottom: 5px;
  font-weight: bold;
}

.modal-content input {
  width: 100%;
  padding: 10px;
  margin-bottom: 15px;
  border: 1px solid #ddd;
  border-radius: 5px;
}

.modal-buttons {
  display: flex;
  gap: 10px;
}

.modal-buttons button {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-weight: 600;
}

#enviarCorreo {
  background: #28a745;
  color: white;
}
#enviarCorreo:hover {
  background: #218838;
}

#cerrarModal {
  background: #6c757d;
  color: white;
}
#cerrarModal:hover {
  background: #545b62;
}

/* ==================== */
/*  SELECT2 MEJORADO    */
/* ==================== */
.select2-container {
  width: 100% !important;
}

.select2-container--default .select2-selection--multiple {
  border: 1px solid #ddd !important;
  border-radius: 5px !important;
  min-height: 42px !important;
}

.select2-container--default .select2-selection--multiple .select2-selection__choice {
  background-color: #0073aa !important;
  border-color: #005a8c !important;
  color: white !important;
  border-radius: 3px !important;
}

.select2-results__option {
  padding: 8px 12px !important;
  font-size: 13px !important;
}

.select2-results__option img.thumb-producto {
  width: 30px !important;
  height: 30px !important;
  margin-right: 8px !important;
}

.select2-results {
  max-height: 300px !important;
}

/* ==================== */
/*  IMPRESIÓN OPTIMIZADA */
/* ==================== */
@media print {
  @page {
    margin: 0.5cm;
    size: A4 portrait;
  }
  
  body {
    background: white !important;
    font-size: 11pt !important;
    line-height: 1.3 !important;
  }
  
  #presupuestoFormulario,
  .acciones-post,
  .modal {
    display: none !important;
  }
  
  .presupuesto-contenido {
    max-width: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
  }
  
  .header-top {
    display: flex !important;
    justify-content: space-between !important;
    align-items: flex-start !important;
    margin-bottom: 10px !important;
    padding-bottom: 10px !important;
    border-bottom: 1px solid #ccc !important;
  }
  
  .logo-header {
    width: 120px !important;
  }
  
  .presupuesto-info h1 {
    font-size: 20pt !important;
  }
  
  .numero-presupuesto {
    font-size: 10pt !important;
  }
  
  .datos-cliente,
  .datos-presupuesto {
    margin-bottom: 15px !important;
    padding: 10px !important;
    border-left: 2px solid #0073aa !important;
    break-inside: avoid;
  }
  
  .datos-cliente h3,
  .datos-presupuesto h3 {
    font-size: 12pt !important;
    margin-bottom: 5px !important;
  }
  
  .datos-cliente p,
  .datos-presupuesto p {
    font-size: 10pt !important;
    margin: 3px 0 !important;
  }
  
  .detalle-titulo {
    font-size: 13pt !important;
    margin-top: 15px !important;
    margin-bottom: 10px !important;
  }
  
  .presupuesto-tabla {
    font-size: 9pt !important;
    margin: 10px 0 !important;
    width: 100% !important;
    table-layout: fixed !important;
  }
  
  .presupuesto-tabla th {
    padding: 6px 4px !important;
    font-size: 9pt !important;
    border-bottom: 1px solid #0073aa !important;
  }
  
  .presupuesto-tabla td {
    padding: 5px 4px !important;
    font-size: 9pt !important;
  }
  
  .producto-col { width: 50% !important; }
  .cantidad-col { width: 8% !important; }
  .precio-col { width: 20% !important; }
  .subtotal-col { width: 22% !important; }
  
  .thumb-producto {
    width: 20px !important;
    height: 20px !important;
    margin-right: 5px !important;
  }
  
  .total-container {
    margin: 15px 0 !important;
    padding: 10px !important;
    border: 1px solid #0073aa !important;
  }
  
  .total {
    font-size: 16pt !important;
  }
  
  .observaciones {
    margin: 15px 0 !important;
    padding: 10px !important;
    font-size: 9pt !important;
  }
  
  .presupuesto-footer {
    margin-top: 20px !important;
    padding-top: 10px !important;
    font-size: 9pt !important;
  }
  
  .presupuesto-footer p {
    font-size: 9pt !important;
    margin: 2px 0 !important;
  }
  
  .presupuesto-footer strong {
    font-size: 10pt !important;
  }
  
  .logo-footer {
    width: 150px !important;
  }
  
  a[href] {
    color: #000 !important;
    text-decoration: none !important;
  }
  
  /* Evitar que se corte la tabla entre páginas */
  table {
    page-break-inside: avoid !important;
  }
  
  tr {
    page-break-inside: avoid !important;
    page-break-after: auto !important;
  }
  
  /* Asegurar que todo quepa en una página */
  .presupuesto-contenido {
    max-height: 26.5cm !important; /* Altura A4 menos márgenes */
    overflow: hidden !important;
  }
}

/* ==================== */
/*  RESPONSIVE          */
/* ==================== */
@media (max-width: 768px) {
  .form-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  
  .header-top {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  
  .presupuesto-info {
    text-align: center;
    margin-top: 10px;
  }
  
  .presupuesto-info h1 {
    font-size: 22px;
  }
  
  .numero-presupuesto {
    font-size: 14px;
  }
  
  .acciones-post {
    flex-direction: column;
  }
  
  .acciones-post button {
    width: 100%;
    min-width: auto;
  }
  
  .presupuesto-tabla {
    font-size: 12px;
  }
  
  .producto-col { width: 45%; }
  .cantidad-col { width: 12%; }
  .precio-col { width: 20%; }
  .subtotal-col { width: 23%; }
}